Sorry if this has already been posted.
Consider this Java code:
public class A {
protected int number;
public A(int number) {
this.number = number;
}
}
public class B extends A{
private B(int number) {
super(number);
}
public static B createFromA(A a) {
return new B(a.number);
}
}
Kotlin equivalent would be:
open class A(protected val number: Int)
class B private constructor(number: Int) : A(number) {
companion object {
@JvmStatic
fun createFromA(a: A) = B(a.number)
}
}
Though a.number
is not visible from the static function.
Could anyone please help me how I could work around that fields with protected
visibility are not visible from inheritors’ static function? Thank you in advance.