1

Which visibility modifier is more permissive: Protected or Internal?

 internal var num = 18
        protected set   // throws an error at 'protected' showing: Setter visibility must be the same or less permissive than property visibility

And I try this also:

 protected var num = 18
        internal set   // throws an error at 'internal' showing: Setter visibility must be the same or less permissive than property visibility
  • ([kotlin docs](https://kotlinlang.org/docs/visibility-modifiers.html#class-members)) I think you cannot combine both, because if you have a internal var, a subclass from another module should see the setter, but should not see the variable – tobi1805 Jul 02 '22 at 13:25

2 Answers2

2

They aren't comparable; neither is more permissive than the other.

A subclass in another module will see protected members, but not internal.

An unrelated class in the same module will see internal members, but not protected.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
0

protected means that the member has the same visibility as one marked as private, but that it is also visible in subclasses.

internal means that any client inside this module who sees the declaring class sees its internal members.

Aymen Ben Salah
  • 489
  • 4
  • 13