Kotlin calling non final function in constructor works

前端 未结 3 847
北海茫月
北海茫月 2021-02-03 17:43

In Kotlin, it warns you when calling an abstract function in a constructor, citing the following problematic code:

abstract class Base {
    var code = calculate         


        
3条回答
  •  时光取名叫无心
    2021-02-03 18:42

    To invoke the functions of the concrete classes in the abstract class use by lazy which allows calling non-final functions.

    From: area = extractArea(room);

    To: area by lazy { extractArea(room) }

    GL

提交回复
热议问题