https://kotlinlang.org logo
#getting-started
Title
# getting-started
h

Hassaan

07/02/2022, 12:33 PM
Isn’t ‘protected’ has lesser visibility than ‘internal’ ? Then why following:
how on this earth?
🙌 1
y

Youssef Shoaib [MOD]

07/02/2022, 1:42 PM
Is the class itself internal? If not, then technically speaking a subclass in another module can see the setter without seeing the getter in the first case, and in the second case someone can see the setter and call it in the same module but without seeing the getter
h

Hassaan

07/02/2022, 2:22 PM
No, Class itself is public
I don't get it. It is throwing errors in both cases meaning that here, visibility modifiers permissiveness depends on usage. But i still don't get it honestly.
y

Youssef Shoaib [MOD]

07/02/2022, 2:34 PM
I think it's because internal and protected aren't necessarily subsets of each other. As in, neither are "more" permissive than the other. They're just not comparable, in a way. I think what you could do here is instead of using
internal
just use a
RequiresOptIn
annotation.
h

Hassaan

07/02/2022, 2:38 PM
Yeah i also reached this conclusion by seeing error in both cases🤣
e

ephemient

07/03/2022, 5:38 AM
`internal`: unrelated classes in same module can access, subclasses in different module cannot `protected`: unrelated classes in same module cannot access, subclasses in different module can neither is a subset of the other
h

Hassaan

07/03/2022, 5:57 AM
I got it later on By the way, thanks
3 Views