static final int b=3;
const val b=3;//只能定义在全局范围 只能修饰基本类型 必须立即用字面量初始化
var x:Any=。。。
val c=when{
x is String -> x.length
x==1 ->2
else -> 20
}
Operators
"hello"=="world" "hello".equals("world")
2+3
2.plus(3)
val list= listOf(1,2,3,4,)
2 in list
list.contains(2)
val map= mutableMapOf(
"hello" to 2,
"world" to 3
)
val s=map["hello"]
map.get("hello")
map["world"]=4
map.set("world",4)
Infix expression
ss".ma("b")
infix fun<A,B> A.ma(that:B):Pair<A,B>
= Pair(this,that)
lambda expressions
val lambda1={
println("hello")
}//lambda表达式返回类型取决于最后一句话的返回类型 可以省略return
val lambda2:(Int)->Unit={
print(it)
}
val lambda3={it:Int->
print(it)
}
val lambda4:Function1<Int,Unit> ={
println(it)
}
lambda1.invoke()==lambda1
lambda4.invoke(1)===lambda4(1)
After rewriting hashcode equals members preferably with constant modifications it may cause memory leaks (there is after deposit hashmap hashset property value changes the cause can not be removed)