https://kotlinlang.org logo
Title
k

Kroppeb

06/04/2019, 11:27 AM
If you are in a function in a supertype and have a variable that is of that type but then smartcasted to a subtype, why do the private functions of the supertype get hidden?
atm I'm getting around it by casting it back to the supertype, but I feel like I shouldn't need to.
k

karelpeeters

06/04/2019, 11:42 AM
Can you give us a minimal example?
e

Evan R.

06/04/2019, 12:43 PM
If a class member is private, that means child class instances are unable to access that member. Smart-casting causes Kotlin to treat the variable as a subtype. If you want this behavior, consider making the class member in question protected rather than private or just keep performing the supertype cast.
k

Kroppeb

06/04/2019, 12:55 PM
It's annoying if you were to refactor a part earlier in the code which results in a smartcast and creates and error later in said function