```internal interface I {} public class Exported {...
# compiler
j
Copy code
internal interface I {}
public class Exported {
    protected val: I? = null
}
Why I cannot have protected property with internal type in FINAL class?
'protected (in Exported)' property exposes its 'internal' type I
The usecase is a public Fragment/Activity with internal ViewModel. We have this viewmodel property abstract in the fragment's parent -> therefore protected.
e
correct me if I’m wrong but if the class is final it means that no classes can inherit from it, which makes protected (visible to itself and children) essentially useless
j
as described, abstract protected in parent is quite useful.
e
ah wait. The problem is different. The issue is that
interface I
is internal. But if
Exported
is public (and not final), it means that anyone could inherit, which - as the message suggests - leads to expose something internal to the public.
j
that's not the issue. the abstract type is obviously public. the implementation will be properly impl detail.
r
I still have no idea what exactly are you trying to do? But, if I understand correctly, you want to have abstract type, with protected internal property that the public final classes will use The problem I see there though, is that public class can't extend internal one either, so the abstract would have to be public too - that means, anyone can extend it, but! - abstract internal type is visible (which it can't obviously)...
j
Copy code
public interface ViewModel {
    public fun doSomething()
}

public abstract class BaseActivity {
    protected abstract val viewModel: ViewModel
}

internal class FinalViewModel : ViewModel {
    override fun doSomething() {}
    fun doSomethingElse() {}
}

public class FinalActivity : BaseActivity() {
    protected override val viewModel: FinalViewModel = FinalViewModel()
}