第一次转换java代码为kotlin,写一下kotlin没了解到的地方吧
var s:String
s!!.trim { it <= ' ' }.length
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
@Throws(IOException::class)
override fun onResponse(call: Call, response: Response) {
}
})
var stu_per_schedules = HashMap<String, ArrayList<String>>()
private set
val dataWhenLoginSuccess: String
get() = htmlData!!.toString()
companion object {
private var tochange = false
}
- 因为kotlin中的类定义同时也是构造函数,这个时候是不能进行操作的,所以kotlin增加了一个新的关键字init用来处理类的初始化问题,init模块中的内容可以直接使用构造函数的参数。
inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var score_Subject_name: TextView
init {
score_Subject_name = itemView.findViewById(R.id.score_Subject_name)
}
}
class Mydapter(private val context: Context) : RecyclerView.Adapter<Mydapter.MyViewHolder>() {
private val context: Context
init {
this.context= context
}
}