What is the purpose of internal lateinit?

4

I converted to Kotlin a simple Fragment with any button. In the alternation, it basically looks like this:

Java

private Button btn;

Kotlin

internal lateinit var btn: Button

What is the goal of internal lateinit ? Would it be replacing private ?

    
asked by anonymous 09.08.2017 / 17:26

1 answer

6

internal is a middle ground between private and public . It is public if it considers that the member can be accessed outside of its object, but is private if it considers that only what is in the same module can access that member.

So it's like you say "look, whoever is a sister class, that is, is part of this module can access this here, or else can not". It is a way of releasing an implementation detail of a class that would be very difficult to do without this, but to protect it from becoming a mess and everyone can access.

Whenever you expose something publicly you have to be careful with all maintenance not to break code that uses that. The private helps because it is contained. The intern is almost this because it is guaranteed that if someone is using it, less is in the same module that you have access to, so it's almost a private one, at least if the project is well organized.

A module is a compilation unit, it looks like a Java package, but it is not well.

% w / w% is still useful for decreasing visibility.

visibility documentation .

private has no direct relationship, I think it has already been answered in How can I "delay" the initialization of a property ? .

    
09.08.2017 / 17:37