Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

👉 About the author

As we all know, life is a long process of constantly overcoming difficulties and reflecting on progress. In this process, there will be a lot of questions and thoughts about life, so I decided to share my thoughts, experiences and stories to find resonance!!

Focus on Android/Unity and various game development tips, as well as various resource sharing (websites, tools, materials, source code, games, etc.)

Welcome to pay attention to the public account [Mr. Empty name] for more resources and communication!

👉 premise

The current environment

2020.3.1 Patch 2 version was last downloaded on October 8, 2021

👉 Practice

😜 Variables and constants

Variable variable definition: var keyword

Var < variable name > : < type > = < initial value >

Definition of immutable variable: the val keyword, a variable that can only be assigned once (similar to a final variable in Java)

Val < variable name > : < type > = < initial value >

The system automatically determines variables without specifying their types. You can also have no initial value, but it must be initialized before you use it

val TempOne = "This is an immutable variable."
var TempTwo = "This is the variable variable."
var TempThree = "Public account: Mr. Empty Name"
val TempFour: String = ""
Copy the code

You just have to have an initialization value before you declare it. (Force write initials to avoid null Pointers?)

When a variable is assigned a value, it infers its own type and cannot change it later. For example, a variable whose initial value is a number cannot then be assigned to a string or call a method of another type. There is one exception for the [Any] type

😜 Basic type

Although the declarations are var and val, Kotlin still has types Byte, Short, Long, Float, Double, String, Noolean, and Any

var numberOne:Int? = 1
var numberTwo:Int? = 1
var numberThree = numberOne
Log.e("TAG"."Sesame seed output 7: Their addresses are equal:" + (numberThree === numberOne))
// The output of the output is equal to the output of the output, which is left as a question for later
Log.e("TAG"."Sesame seed output 7: Their addresses are equal:" + (numberOne === numberTwo))
Log.e("TAG"."Sesame seed output 7: Their addresses are equal:" + (numberThree === numberTwo))
Log.e("TAG"."Sesame seed output 7: Their contents are equal:" + (numberOne == numberTwo))
Copy the code

//2021-10-13 10:30:42.460 3103-31093 /cn. Appstudy E/TAG: True //2021-10-13 10:30:42.460 31093-31093/cn. Appstudy E/TAG: True //2021-10-13 10:30:42.460 31093-31093/cn. Appstudy E/TAG: Appstudy E/TAG: true //2021-10-13 10:30:42.460 31093-31093/ cn.appStudy E/TAG: true \

Array types are also essential

  var listOne = arrayOf(1.2.3)
        var listTwo = intArrayOf(1.2.3)
        var listThree = arrayListOf<String>()
        listThree.add("It is")
        listThree.add("Array")
        listThree.add("List")
Copy the code

An array must have a loop read. See the loop Control section for details

😜 string

Strings support multi-line characters, using [” “”] three double quotation marks, but multi-line application scenarios are rare, small space has developed several products have not used.

var strignOne = "Public Account:"
var strignTwo = "Mr. Empty Name"
if (strignOne.equals(strignTwo)) {
    Log.e("TAG"."Sesame seed Output 6: Their contents are equal")}else {
    Log.e("TAG"."Sesame seed output 6: They vary in content.")}Copy the code

👉 other

📢 author: Kom and Kom in Kom

📢 reprint instructions – be sure to specify the source: Zhim Granular’s personal home page – column – Nuggets (juejin. Cn)

📢 welcome to like 👍 collect 🌟 message 📝