Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setter for a boolean variable named like isActive

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 ?

like image 871
vaibhav bindroo Avatar asked Jan 31 '11 13:01

vaibhav bindroo


People also ask

How should Boolean variables be named?

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.

Should boolean return setter?

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.

How do you name a boolean field?

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 .

How do you name a boolean variable in Python?

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.


2 Answers

primitive boolean field getters are created as isFieldName. So in Ibatis you should give the property name as active not isActive

like image 64
fmucar Avatar answered Oct 16 '22 08:10

fmucar


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.

like image 28
Qwerky Avatar answered Oct 16 '22 08:10

Qwerky