Having a base class I would like it and its descendent class be visible only internally:
internal abstract class BaseClass
internal open class Class_A: BaseClass()
internal open class Class_B: Class_A()
In place where the list of Class_A (may also contains Class_B in it), would like to make it protected for its own descendent class to access this list
open class User {
// got error: 'protected' property exposes its internal return type"
protected var class_A_list: List<Class_A>? = null
}
class User_descendent: User() {
// can access the class_A_list
}
How to let the descendent class access the instance of some "internal" class?
The above error is protecting the
internalclasses to be accessed by other classes which are not in the same module of the internal class. If it was allowed, then you can't guarantee that the classUserwould be only inherited by the classes in the same module.So if you want to make the
class_A_listprotected, you have to make theUserclassinternal. By doing so, it will guarantee that,Userwill be inherited by the classes which is in the same module. The following should be fine: