Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Lateinit modifier for Kotlin usage skills

Shulou Source: shulou.com Published: 2022-06-03 06:48:32 10月26日 Update

The question in the Kotlin definition of variables or attributes need to initialize the value, and the definition of variables or attributes are private by default, then there is a way not to assign values at the time of definition, the answer is yes. The definition of attribute or variable is divided into the following two cases: 1, ordinary attribute / variable definition; 2, using annotations to define variable / attribute; for 1 case, the solution is ordinary definition, with the keyword lateinit modified.

For two cases: it may change slightly, if you use kapt to process annotations before using lateiinit to modify:

After decorating with lateinit:

Note: lateinit-decorated variables / attributes cannot be primitive data types

Tags: Variables attributes situations ordinary that is methods annotations primitive do not use keys keywords data methods times answers types questions changes processing usage techniques Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Huawei Microsoft OPPO Reno