Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - Generating Getters/Setters

Tags:

java

eclipse

There is an option in Eclipse (Preferences -> Java->Code Style)

It allows "is" Prefix for getters if the return is boolean.

My question why does it not do the prefixing if the return is the wrapper class (Boolean) ?

like image 472
user2817836 Avatar asked Sep 26 '13 08:09

user2817836


People also ask

How do I generate getters and setters in spring boot?

After you have created the variables in the class, right click, select Source, select Generate Getters and Setters.


1 Answers

This is simply because per the java beans specification/convention/implementation is prefix is only intended for primitive objects.

You can take a look at the PropertyDescriptor class source (getRealMethod):

 if (readMethodName == null) {
    Class type = getPropertyType0();
    if (type == boolean.class || type == null) {
        readMethodName = "is" + getBaseName();
    } else {
        readMethodName = "get" + getBaseName();
    }
    }

So eclipse is only conforming to this.

Edit: now why the property descriptor is made this way is another question, probably Java folks decided that the possibility of null return type and the "is" prefix may be misleading.

like image 148
Kemoda Avatar answered Oct 11 '22 20:10

Kemoda