Larry Garfield
05/30/2024, 4:26 PMSam
05/30/2024, 4:28 PMLarry Garfield
05/30/2024, 4:31 PMSam
05/30/2024, 4:46 PMval
with a var
.Larry Garfield
05/30/2024, 4:47 PMGleb Minaev
05/30/2024, 5:23 PMLarry Garfield
05/30/2024, 5:24 PMBenoît Liessens
05/30/2024, 8:06 PMkqr
05/31/2024, 7:23 AMModifiers
The access specifier for an overriding method can allow more, but not less, access than the overridden method. For example, a protected instance method in the superclass can be made public, but not private, in the subclass.
You will get a compile-time error if you attempt to change an instance method in the superclass to a static method in the subclass, and vice versa.
https://docs.oracle.com/javase/tutorial/java/IandI/override.htmlSam
05/31/2024, 7:23 AMSam
05/31/2024, 7:25 AMclass Foo {
private String foo = "foo";
public String getFoo() { return foo; }
private void setFoo(String foo) { this.foo = foo; }
}
class Bar extends Foo {
private String foo = "foo";
public String getFoo() { return foo; }
void setFoo(String foo) { this.foo = foo; }
}
So I still don't see any technical reason why it shouldn't work in Kotlin. It seems like it just isn't currently allowed.CLOVIS
05/31/2024, 8:18 AMBar
, getFoo()
and super.getFoo()
may return different values, which I believe is very confusing.CLOVIS
05/31/2024, 8:20 AMabstract class Foo(
open var foo: Int,
)
class Bar(
override var foo: Int,
)
but I'd argue making more of these cases is a bad idea.Larry Garfield
05/31/2024, 1:37 PMCLOVIS
05/31/2024, 1:41 PMCLOVIS
05/31/2024, 1:43 PMabstract val
in the parent class.