Operator Elvis operator?:
Val a = b?. Length?:-1
Safe conversion as. Transformation unsuccessful return NULL NULL safety
var a:string? = null
a?. Length//a is null then pass, NOT NULL to call
a!!. length//Parabolic anomaly
Type-identifier is-scope operator: in
For (i in 1..5 Step 1) {} for
(i-5 Downto 1 Step 2) {}
The contents of the three double quotes between the multiline input characters will be preserved as the extension function run calls the function block, within the block this refers to the return value of the calling object as the last row
Val result = "haha". run{
println (this)
"I ' m result"
}
println (Result)
Apply with run, within the function block this refers to the object return value as the object itself let function block it refers to this object return value last row also function block it refers to the object's return value as the object itself with the object as a function parameter this refers to the object returning the value as the last Yes
Val result = with (' haha ') {
println (this)
' result '
}
println (Result)
Modifiers private can only be visible to the file in which they are located, and cannot be used in files other than the definition of this class protected can be visible to members themselves and their successors (for example, classes and its subclasses) internal to the entire module where the public The least restrictive modifier. This is the default modifier delegate Property A property has some of the same behavior, and using lazy or observable can be fun to reuse. Instead of declaring those same code over and over again https://wangjiegulu.gitbooks.io/kotlin-for-android-developers-zh/content/biao_zhun_wei_tuo.html
Standard delegates
By lazy by
observable by
Delegates.notnull () by
map
Custom delegates:
Inherit Readwriteproperty by
Delegatesext.notnullsinglevalue ()
Operator
Sealed type Sealed
Like enumerations, except that instances of enumerations are unique, and sealed classes can have many instances, and they can have different states.
Sealed class Option<out t> {
class some<out t>: Option<t> ()
object None:option<nothing> ;()
}
Reference:
-Https://wangjiegulu.gitbooks.io/kotlin-for-android-developers-zh/content/biao_zhun_wei_tuo.html