I have a property called isActive in my pojo class. When I generated the accessors for this property using Eclipse IDE, it generates following getters and setters
Getter : isActive()
Setter : setActive()
However, when I try to write this property using ibatis framework by mentioning property name as "isActive" , it cribs about not able to find any WRITEABLE propery named 'isActive'. The problem I think lies with not able to deduce the correct property name by inferring setter as setIsActive().
What is the best way to go about this without changing the property name or getter ?
When naming booleans, you should avoid choosing variable names that include negations. It's better to name the variable without the negation and flip the value.
And the answer is no, returning bool is a terrible idea. The best answer is to create a user defined type (class) for month that simply can not have an incorrect value. The next best thing is either assert or an exception.
It is highly recommended to use an adjective to name a boolean field. If you generate getter and setter using IntelliJ, you will find out that the getter is isCurrent() for both of boolean fields current and isCurrent .
Function names should be lowercase, with words separated by underscores as necessary to improve readability. Typically, people start a function with is (e.g. is_palindrome ) to describe that a boolean value is returned.
primitive boolean field getters are created as isFieldName
. So in Ibatis you should give the property name as active
not isActive
The pojo naming convention expects boolean
types called xxx
to have methods isXxx
and setXxx
.
In your case your pojo should look like;
public class MyPojo
{
private boolean active;
public boolean isActive()
{
return active;
}
public void setActive(boolean active)
{
this.active = active;
}
}
You can demonstrate this yourself by creating a class in your IDE and defining the private boolean active
variable, and then getting the IDE to generate getters and setters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With