Re: abbreviating getters and setters proposal for java 8

neugens.limasoftware@gmail.com neugens.limasoftware at gmail.com
Fri May 20 06:02:21 UTC 2011


If this reall must be done, why not use just annotations instead?

They make code readable rather than a collection of IRC smileys...

I don't think that saving 3 characters makes life so much easier, especially with modern IDEs that autocomplete everything, so the only benefit I see is that the compiler or the vm generates those accessors for you, but in client code you still use the getters/setters like before, which would help having clear code.

Mario
-- 
Sent from HTC Desire...

pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF

http://www.icedrobot.org

Proud GNU Classpath developer: http://www.classpath.org/
Read About us at: http://planet.classpath.org
OpenJDK: http://openjdk.java.net/projects/caciocavallo/

Please, support open standards:
http://endsoftpatents.org/


----- Reply message -----
Da: "Mikhail Grushinskiy" <mgrushinskiy at gmail.com>
Data: ven, mag 20, 2011 05:44
Oggetto: abbreviating getters and setters proposal for java 8
A: <discuss at openjdk.java.net>

Hello JDK developers,

I have one proposal for java 8.
Java getters and setters are quite verbose. There was a number of proposals
to address it but none was
ever included into java. So here is another one.

Instead of:

public class Class1 {

    private Long      a1;
    private boolean   b1;
    private Character c1;

    public Long getA1() {
        return a1;
    }

    public void setA1(Long a1) {
        this.a1 = a1;
    }

    public boolean isB1() {
        return b1;
    }

    public void setC1(Character c1) {
        this.c1 = c1;
    }
}

Allow writing it like following (using ><  .> and .< notation)
 where
     >< abbreviates both getter and setter
     .> abbreviation for a getter
     .< abbreviation for a setter

1.

public class Class1 {

    private Long      a1 ><;
    private boolean   b1 .>;
    private Character c1 .<;
}

2. Implementing getters and setters (note that syntax for a setter is
consistent with java 7 lambda expression):

public class Class1 {

    private Long      a1 ><;
    private boolean   b1 .> {true;};
    private Character c1 .< {Character x -> c1 = x;};
}

3. Calling getters and setters

Class1 obj1 = new Class1();

obj1.>a1; // same as obj1.getA1();

obj1.<a1(val1); // same as obj1.setA1(val1);


4. Annotating getter or setter

public class Class2 {

    private String s1 @ValidDateString .<;

}

5. Possible alternatives to .> and .<

 instead of .> reserve |>  or ->
 instead of .< reserve <|  or <|
 instead of >< reserve <-->


Thanks,
--MG


More information about the discuss mailing list