Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Lateinit modifier for Kotlin usage skills

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report