在Kotlin中使用委托时,为什么isBackgroundWindow返回错误?

时间:2018-11-27 07:08:29

标签: android kotlin

我希望为var let map = { "KeyA" : [123,111,100], "KeyB" : [147,123,789,111], "KeyC" : [147,148,789] }; let checker = (obj, keys, val) => { return keys.every(k => val.every(v => obj[k].includes(v))); } console.log(checker(map, ["KeyA", "KeyB"], [123, 111]));设置一个值,但是isBackgroundWindow会导致空错误,为什么?

BTW,代码0 代码1 错误。

代码0

private var isBackgroundWindow: Boolean by PreferenceTool(this@UIHome, getString(R.string.IsBackgroundName) , false)

代码1

   private lateinit  var isBackgroundWindow: Boolean

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_home)  

        isBackgroundWindow= PreferenceTool(this, getString(R.string.IsBackgroundName) , false)
    }

代码A

private var isBackgroundWindow: Boolean by lazy {
        PreferenceTool<Boolean>(this@UIHome, getString(R.string.IsBackgroundName), false)
    }

代码B

class UIHome : AppCompatActivity() {
    private var isBackgroundWindow: Boolean by PreferenceTool(this@UIHome, getString(R.string.IsBackgroundName) , false)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_home)
        isBackgroundWindow=true
    }
}

0 个答案:

没有答案