The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

siebica (3) [Avatar] Offline
#1
According to the JavaBeans v1.01 specification, the only place allowed for a getter that starts with the is prefix instead of the usual get prefix is when you write a getter for a boolean primitive property (8.3.2 Boolean properties). The use of the is prefix for Boolean references is normally not allowed.

The v8 of the MEAP specifies at page 27 that
You may begin getter methods for Boolean properties with is instead of get.
I modified the hello world code example and you can indeed use "is" styled getters for Boolean properties. After checking the Hibernate code (org.hibernate.property.BasicPropertyAccessor#getterMethod(Class, String)), I noticed it's even possible to have an "is" styled getter for any kind of property. I changed the getter for org.jpwh.helloworld.Message's text property as below:
from
public class Message {

    private Long id;

    private String text;
    
    ...

    @Id
    @GeneratedValue(...)
    public Long getId() {...}

    public String getText() {...} // "get" getter style working
    
    ...
}
to
public class Message {

    private Long id;

    private String text;
    
    ...

    @Id
    @GeneratedValue(...)
    public Long getId() {...}

    public String isText() {...} // "is" getter style still working
    
    ...
}
and it's working.

Is this kind of behavior desired? I remember encountering a bug once when calling a web service because the JAXB implementation was having a similar issue to this one.
Christian Bauer (56) [Avatar] Offline
#2
Most tools are lenient and accept either form, independent of property type. In fact, I've never encountered a problem with this so I don't think it's even worth speculating about.