【发布时间】:2021-02-28 22:29:38
【问题描述】:
为什么在 print 语句中没有带外括号的括号,这是什么意思?
class outer() {
var name = "mr X"
class nestedclass {
var description = "Inside the nested class"
var id = 101
fun foo() {
println("id is $id")
}
}
}
fun main() {
println(outer.nestedclass().description) why there is no () with outer?
outer.nestedclass().foo()
var obj = outer.nestedclass()
obj.foo()
println(obj.description)
}
【问题讨论】:
-
这是不可编译的。你确定 Outer 没有被声明为对象吗?
-
@Tenfour04 编译到这里就OK了(把
println()后面的备注注释掉)。 -
没关系。我被小写的类名和在移动设备上阅读它所迷惑。
标签: kotlin static inner-classes parentheses outer-classes