Record the usage of some Kotlin _kotlin

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.