https://kotlinlang.org logo
Title
m

Marc Knaup

02/05/2019, 7:42 PM
Is it possible to make a class
open
to its own module only but not to "the public"?
r

Ruckus

02/05/2019, 7:50 PM
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

Marc Knaup

02/05/2019, 7:51 PM
no,
internal
only for the
open
part
the class itself should be
public
r

Ruckus

02/05/2019, 7:51 PM
Ah, I read "open" and thought "visible", sorry
m

Mike

02/05/2019, 8:45 PM
Perhaps 'internal open' then?
m

Marc Knaup

02/05/2019, 8:45 PM
Then the whole class is unusable outside the module 🙂
m

Mike

02/05/2019, 8:47 PM
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

Marc Knaup

02/05/2019, 8:48 PM
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

Mike

02/05/2019, 8:50 PM
Hmm, I think your idea of internal constructor should achieve that.
m

Marc Knaup

02/05/2019, 8:50 PM
Wasn't my idea but yes 🙂
n

Nikky

02/05/2019, 10:33 PM
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