1,!!!!! (Executes if the current object is not empty. Objects using this symbol will throw an exception if null is present.)

2.? Var STR :String? =null

3, method extension (e.g. long.toString (l:Long):String)

4. What is the scope of the Fun isLetter(c: Char) = c in ‘a’.. Fun isNotDigit(c: Char) = c! in ‘0’.. ‘9’ // is not in the range 0 to 9

5. Is is of some type (like Instanceof in Java)? Is (not of a type, as opposed to IS)

6, as mandatory type change? As cast. If the cast fails, null is returned. No exception is thrown

Var defines a variable whose value can be modified. Val defines a variable whose value cannot be modified (similar to final in Java).

Eight,Var STR: String = println ($STR) $STR: String = println ($STR)

Kotlin code fun faceScoreDescn(score:Int):String{var descn:String; When (score){10 -> descn = “9 -> descn =” 8 -> descn = “7 -> descn =” 6 -> descn Public String faceScoreDescn(int score){String desCN =null; Switch (){case 10: descn = “descn “; break; case 9: …..

Default descn = "ugly"} return descnCopy the code

}

Override: parent method

Fun: method declaration

Fun sum(a: Int,b: Int): Int{retrun a + b}

Fun sum(a: Int,b: Int) : Int = a + b

Fun sum(a: Int,b: Int) = a + b

fun maxOf(a: Int, b: Int): Int { if (a > b) { return a } else { return b } }

Fun maxOf(a: Int, b: Int) = if (a > b) a else b

13. The Unit method returns no value. Unit is conceptually equivalent to Void

Fun showMsg(MSG :String):Unit{println(MSG)} fun showMsg(MSG :String){println(MSG)// The println is in logcat }

Open class A {open fun f() {print(“A”)} fun A () {print(“A”)}} interface B {var name: Fun f() {print(“B”)} // The default member of the interface is ‘open’ fun B () {print(“B”)}

} class C() : A(), B {override var name: String = “C” Override fun f () {super. F () / / call A.f () super. B. f () / / call ()}}

Start a list food = listOf(“orange”, “apple”, “bear”, “tomato”)// Read only

A raw String is represented by triple quotation marks (“””). Its content is unescaped and can contain newlines and any character

    val text = """
           for(c in "foo")
           print(c)
           """
    println(text)
Copy the code

The format of the string content wrapped in three double quotes remains unchanged

 val text = """
           |for(c in "foo")
           |print(c)
           """.trimMargin("|")
    println(text)
Copy the code

17. Bit operation

The equality operator

19. The modifier private means accessible only within the class (and all its members); Protected — like private, and also accessible in subclasses; Internal – Anywhere within this module that can access this class can also access its internal members; Public – anywhere that can access this class can also access its public members.

In Kotlin, the outer class cannot access the private members of its inner class

20, lateinit

What if, when you define a variable (for example, a member variable), you don’t want it to be empty, but you don’t want to initialize it when you define it? Use the lateinit keyword

Lateinit var test:String // Correct lateinit val test:String // error lateinit var test:Float // Error

lateinit modifier is allowed only on mutable properties
lateinit modifier is not allowed on primitive type properties
Copy the code

As you can see, the LateInit modifier can only modify non-nullable types and does not allow modification of underlying types (int, double, Boolean, etc.).

21, For loop Java:

For (int I =0; i < 5; I++) {}

Kotlin:

for(i in 0..4) { }

Item.method () {for (item in listData) {

For (I in listdata. indices) {

For ((I, item) in list.witnindex ()) {// witnIndex())

Listdata.foreach {it.method()} // variant of the for loop