我刚刚开始研究Kotlin编程语言,它比Java酷得多.我对静电的方法和领域有一些疑问:
Q1: Official document says
Kotlin还可以为名为中定义的函数生成静电方法 对象或伴随对象(如果您将这些函数注释为 @JvmStatic.
But if you see below I can access bar()
method as a static method, which works without using @JvmStatic
annotation. But on official doc its throwing error -> Kotlin static method.
Class C{
companion object{
@JvmStatic
fun foo() { }
fun bar();
}
}
fun main(args: Array<String>) {
C.foo();
C.bar(); //this line works fine
}
Q2: Do I really need 100 and 101 to make things static?