I just had a little surprise in a Webapp, where I’m using EL in .jsp pages.
I added a boolean property and scratched my head because I had named a boolean “isDynamic”, so I could write this:
<c:if test="${page.isDynamic}">
...
</c:if>
Which I find easier to read than:
<c:if test="${page.dynamic}">
...
</c:if>
However the .jsp failed to compile, with the error:
javax.el.PropertyNotFoundException: Property 'isDynamic' not found on type com...
I turns out my IDE (and it took me some time to notice it), when generating the getter, had generated a method called:
isDynamic()
instead of:
getIsDynamic()
Once I manually replaced isDynamic() by getIsDynamic() everything was working fine.
So I’ve got really two questions here:
-
is it bad to start a boolean property’s name with “is”?
-
wether it is bad or not, didn’t IntelliJ made a mistake here by auto-generating a method named isDynamic instead of getIsDynamic?
Sensitive subject, but in my opinion it is bad. The variable name should not denote a question, but a statement. E.g.
pageIsDynamic,dynamicalordynamicallyGenerated. There is however no clear coding convention for this. As long as you’re consistent throughout the coding, either way won’t harm that much.No, it didn’t. The Javabean specification states that it is allowed to prefix boolean getter method names with
isas well. It is usually preferred aboveget. As every other decent IDE, IntellIJ just adheres this specification. Eclipse and Netbeans would do the same. Here’s an extract of chapter 8.3.2: