自用Kotlin

1.单例

/**
 * Io 串口
 */
class IoBoardModel private constructor() {
    val TAG = "IoBoardModel"
    lateinit var serialPort: SerialPortProxy

    companion object {
        val instance by lazy {
            IoBoardModel()
        }
    }

    fun init(context: Application) {
        Log.e(TAG, "init: 方法执行了")
        serialPort = SerialPortProxy(context)
    }
}

你可能感兴趣的:(Kotlin,kotlin)