eygraber
02/27/2024, 10:08 PMprotected property exposes its internal type BarImpl
even though FooImpl
isn't open. Since bar
is protected, only subclasses of FooImpl
could access it, but that isn't possible because FooImpl
is final. So why is there an issue with making FooImpl
public?
abstract class Foo<B : Bar> {
protected abstract val bar: B
}
class FooImpl : Foo<BarImpl> {
override val bar: BarImpl
}
internal class BarImpl : Bar
Klitos Kyriacou
02/28/2024, 11:30 AMval bar
property. Even if you remove this property, there is still a problem with the fact that BarImpl
is a type parameter in the abstract class FooImpl
extends. Consider this:
// MODULE A
interface Bar
abstract class Foo<B : Bar>
class FooImpl : Foo<BarImpl>()
internal class BarImpl : Bar
// MODULE B
inline fun <reified T: Bar> foo(x: Foo<T>) {
println(T::class)
}
fun main() {
foo(FooImpl())
}
Now if there was no compiler error, and fun foo
and fun main
ran in another module, you'd be able to see an internal class from another module.eygraber
02/28/2024, 2:38 PMFoo
to
class FooImpl : Foo<Bar>()
then there's no error about the type parameter anymore, but there is still one about the property.