Android是使用任务(task)来管理Activity的,一个任务就是一组存放在栈里的Activity
的集合,这个栈也被称作返回栈(back stack)。
val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape")
val builder = StringBuilder()
builder.append("Start eating fruits.\\n")
for (fruit in list) {
	 builder.append(fruit).append("\\n")
}
builder.append("Ate all fruits.")
val result = builder.toString()
println(result)

👇
val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape")
val result = with(StringBuilder()) {
	append("Start eating fruits.\\n")
	for (fruit in list) {
		 append(fruit).append("\\n")
	}
	append("Ate all fruits.")
	toString()
}
println(result)
val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape")
val result = StringBuilder().run {
	append("Start eating fruits.\\n")
	for (fruit in list) {
			append(fruit).append("\\n")
	}
	append("Ate all fruits.")
	toString()
}
println(result)
val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape")
val result = StringBuilder().apply {
	append("Start eating fruits.\\n")
	for (fruit in list) {
		append(fruit).append("\\n")
	}
	append("Ate all fruits.")
}
println(result.toString())
注解方式:
class Util {
	 fun doAction1() {
		 println("do action1")
	 }
	 companion object {
		 @JvmStatic
		 fun doAction2() {
			 println("do action2")
		 }
   }
}
注意,@JvmStatic注解只能加在单例类或companion object中的方法上,如果你尝试加在
一个普通方法上,会直接提示语法错误。

顶层方法:
指的是那些没有定义在任何类中的方法,比如我们在上一节中编写的main()方法。
Kotlin编译器会将所有的顶层方法全部编译成静态方法,因此只要你定义了一个顶层方法,
那么它就一定是静态方法。