Is a Boolean attribute name prefix “is” still a valid java bean?

I just noticed something I didn't know

private boolean isCertified;

  public boolean isCertified() {
    return isCertified;
  }

  public void setCertified(boolean certified) {
    isCertified = certified;
  }

IntelliJ generates the following getters and setters By the way, Longmu island produces the same aspirator and setter

I would expect:

private boolean isCertified;

  public boolean isIsCertified() {
    return isCertified;
  }

  public void setIsCertified(boolean certified) {
    isCertified = certified;
  }

That's why I usually don't use my Boolean attribute prefix ì s and despise the fact that I think attribute names become more readable

What I usually write is like:

private boolean certified;

  public boolean isCertified() {
    return certified;
  }

  public void setCertified(boolean certified) {
    certified = certified;
  }

So I want to know:

There is a property named isXXX and a getter that is isXXX instead of isisxxx: is it a valid java bean definition? > Are there any other hidden java bean roles that I might want to know to improve the readability of the code?

thank you

Solution

AFAIK, the naming pattern of fields is not part of the JavaBeans specification

The JavaBeans specification (and others) specifies the concept of "properties"

The properties of a class are identified by the methods of the class (named after a pattern)

These areas are irrelevant In fact, there is not even a field of property

That is, naming fields after attribute names is still a good practice More importantly, tools that need to access fields (such as refactoring support in the IDE) will handle these fields correctly

No, the getter of the property is XXX, which requires isisxxx() (for Boolean values) or getisxxx()

But it's another matter

If you have a way:

boolean isXyz()

Then you have a readable property XYZ

If you have a way

boolean isIsXyz()

Then you have a readable attribute isxyz

For more information, check the introspector class, tutorial, or JavaBeans specification:

http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html

http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138795.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
***
下一篇>>