1. ? !! !
val str:String! = “” //无法声明,临时变量,说明这是Kotlin调用Java代码产生的,如果要使用,最好用可空类型
val str:String? = “” //可空类型
val str:String!! = “” //1.强制转换;2.不能为空
2. .javaClass vs ::class.java
The difference in these two constructs is that, for an expression foo of static (declared or inferred) type Foo:
foo.javaClass
is typed as Class<Foo>
foo::class.java
is typed as Class<out Foo>
In fact, the latter is more precise, because the actual value that foo evaluates to can be an instance of not Foo itself but one of its subtypes (and it’s exactly what’s denoted by the covariant out Foo).
As @marstran correctly noted in the comment on the question, .javaClass once was considered to be deprecated (see the Kotlin 1.1 RC announcement) because it can break type safety (see below), but it was afterwards left as-is because it was widely used and replacing it with the alternative of ::class.java would require adding explicit unchecked casts in the code.
3. return@label
1 | fun foo(ints: List<Int>) { |
https://stackoverflow.com/questions/40160489/kotlin-whats-does-return-mean
Non-local returns
In Kotlin, we can only use a normal, unqualified return to exit a named function or an anonymous function. This means that to exit a lambda, we have to use a label, and a bare return is forbidden inside a lambda, because a lambda cannot make the enclosing function return:
https://kotlinlang.org/docs/reference/inline-functions.html#non-local-returns