class SecondActivity : AppCompatActivity() {
var context: Context? = this;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
for(i in 1..10 step 2){
// Log.e(context?.packageName+"")
if(i in 1..5){
Log.e("i","$i")
}
}
User().username;
User().sex;
//最后一行 / return的表达式
User().let {
it.username
it.sex
999
}
//返回对象
var user = User().also {
it.username
it.sex
}
user.sex
//省略调用直接用属性
with(User()){
Log.e("=a=","$username==$sex")
}
//结合了with 与 let 返回最后一行
User().run {
Log.e("=a=","$username==$sex")
9999
}
//结合了with 与 also 返回对象本身
var user1 = User().apply {
Log.e("=a=","$username==$sex")
}
user1.sex
}
}
Kotlin基本操作符
最新推荐文章于 2024-04-18 05:46:27 发布