Search code examples
javagetter-setterlanguage-design

Are there any plans for Java to add implicit Getters and Setters?


Does anyone know if there is a plan to add in implicit getters and setters for Class variables?

I'm thinking of the current Scala code that allows this already. Something like the following, where if you don't define a getter/setter it uses the value, but if you do define a getter/setter for the value it uses that instead of a direct variable call.

class A{
    int value = 3;
}

class B{
    int value = 3;
    public int value(){
        return value;
    }
}

// in some method
A a = new A();
System.out.println(a.value); 
B b = new B();
System.out.println(b.value); // <-- no () for accessing value even though it uses the getter

Solution

  • not Java per se, but there is this Project Lombok