-
Notifications
You must be signed in to change notification settings - Fork 133
Open
Labels
Description
When using delegation, property-style access doesn’t work as expected for delegated members. Instead of allowing b.foo, the compiler requires b.foo(), even though the property is defined in the delegated type.
interface MyIntf {
String foo();
}
record A(String foo) implements MyIntf {}
record B(@link A a, String b) implements MyIntf {}
A a = new A("foo");
B b = new B(a, "b");
String foo = a.foo; // Works as expected
b.foo; // Not working, b.foo() is required.Environment:
- Java/JDK version: Jdk 25
- Manifold version: 2025.1.27
Related question: Should it be possible to define the getters in the interface as properties? It works for normal classes, but not for records:
interface MyIntf {
@val String foo;
}
record A(String foo) implements MyIntf {} // ERROR
class C implements MyIntf {
@val @override String foo; // OK
}I'm not sure this is even possible. The interface defines the contract - in this case, a getter method. However, since a regular getter method is generated, it doesn’t align with the record accessor naming convention.
I think many of these issues could be avoided if Java simply followed the standard getter conventions, but that's not something that can be changed anymore...
Reactions are currently unavailable