Is it possible to make a class `open` to its own m...
# announcements
m
Is it possible to make a class
open
to its own module only but not to "the public"?
r
You mean internal? https://kotlinlang.org/docs/reference/visibility-modifiers.html#packages
If you mark it
internal
, it is visible everywhere in the same module
m
no,
internal
only for the
open
part
the class itself should be
public
r
Ah, I read "open" and thought "visible", sorry
m
Perhaps 'internal open' then?
m
Then the whole class is unusable outside the module 🙂
m
I guess we're not understanding the use case correctly, then.
Maybe a sealed class? But that obviously means everything has to be defined in one file. The inheriting classes can be used outside the module but Noone can extend the 'parent'.
m
A class which is usable outside the module, and subclassable only within the module.
internal
constructor should satisfy that 🙂
sealed class
is limited to one file and also cannot be instantiated directly, be it in the same file or anywhere else.
m
Hmm, I think your idea of internal constructor should achieve that.
m
Wasn't my idea but yes 🙂
n
you could make a internal open class and a (final) class that extends i without changes so you can use it outside, maybe ? possibly implementating a interface by delegation can trick the compiler here