kotlin第二篇

第一次转换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) {

                }
            })
  • 下面这样只能set不能set
var stu_per_schedules = HashMap<String, ArrayList<String>>()
        private set
  • 一个变量的get方法可以这样写
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
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值