JavaBeans: What is the difference between an attribute and a property?

The JavaBean section of my change list states that I should know "the difference between an attribute and a property." I can not find the difference between the two. I know that JavaBeans uses properties, and regular Java classes use attributes (or at least what I was taught to call them), but I don’t see the real difference.

Is this related to getter / setter methods?

thank

+5
source share
2 answers

Examples

Property and attribute are equivalent

private int age;

public int getAge() {
    return age;
}

public void setAge(int age) {
    this.age = age;
}

The property is ageconverted to an attribute.personAge

private int personAge;

public int getAge() {
    return personAge;
}

public void setAge(int age) {
    this.personAge = age;
}

The property is synthesized, no attribute

In this case, the property is read-only:

private int age;
private Sex sex;

public boolean isFemaleAdult() {
    return sex == Sex.FEMALE && age >= 18
}

:

... .

:

. , .

+7

atype getXXX()/void setXXX(atype ). .

+4

All Articles