https://kotlinlang.org logo
Title
a

albertgao

03/21/2018, 12:28 AM
In my package
a.b.c
, I have an
abstract
class named
BaseUser
which I use it to share some code. But I want this class
BaseUser
to be internal in the
a.b.c
. Such that, I can create
User:BaseUser
in
a.b.c
. But the user of package can’t refer
a.b.c.BaseUser
. I tried the
protected
modifier. Not work, when I try to build, it said
This type is final, so it cannot be inherited from
,
Cannot access 'BaseUser': it is protected in 'a.b.c'
and
'public' subclass exposes its 'protected (in ?)' supertype BaseUser
. No luck with
internal
too How to make this work? 🤔
g

groostav

03/21/2018, 12:35 AM
you cant make this work like your thinking, if you make object X public, then its entire superclass tree must also be public in kotlin
😢 1
a

albertgao

03/21/2018, 12:38 AM
Thanks.
g

gildor

03/21/2018, 2:21 AM
Use composition instead of inheritance to dothat
a

albertgao

03/21/2018, 3:28 AM
@gildor Thanks. More hints for this? 😄
g

gildor

03/21/2018, 3:29 AM
Do not extend class, but create an instance of private class inside of your public class and delegate method calls