在下面的代码中:
var verticesCount: Int // to read a vertices count for graph
// Reading until we get a valid vertices count.
while (!Assertions.checkEnoughVertices(
verticesCount = consoleReader.readInt(null, Localization.getLocStr("type_int_vertices_count"))))
// The case when we don't have enough vertices.
println(String.format(Localization.getLocStr("no_enough_vertices_in_graph"),
Assertions.CONFIG_MIN_VERTICES_COUNT))
val resultGraph = Graph(verticesCount)
我们在最后一行收到下一个错误:
Error:(31, 33) Kotlin: Variable 'verticesCount' must be initialized
Assertions.checkEnoughVertices接受一个安全类型变量作为参数 (verticesCount: Int),因此 verticesCount 不可能在此处未初始化或为 null(我们在这些行上没有得到相应的错误)。
当已经初始化的变量再次变为未初始化时,最后一行发生了什么?