I am making an application that uses Drools planner.
The @ValueRangeFromSolutionProperty
is supposed to refer to a property from another class (NQueens
in this case). From the JavaDocs for @ValueRangeFromSolutionProperty:
propertyName
The property name of which exists a getter on the Solution that returns a Collection.
But I noticed an inconsistency: the annotator uses the property rowList
from NQueens
. But rowList
(as opposed to RowList
) is a private variable (see snippets below). If it were supposed to infer a property by introspection (from it's getter and setter methods), shouldnt it be spelled RowList
as in getRowList()
?
Question: How does Java infer (introspect) the property name (case and all) from the getter methods?
Or does the @ValueRangeFromSolutionProperty
access the private variables directly?
Background details:
From Queen.java
, a class that represents a queen on a chessboard:
public class Queen extends AbstractPersistable {
....
@ValueRangeFromSolutionProperty(propertyName = "rowList")
public Row getRow() {
return row;
....
From NQueens.java
, the class from which the @ValueRangeFromSolutionProperty
gets it's property from:
public class NQueens extends AbstractPersistable implements Solution<SimpleScore> {
...
private List<Column> columnList;
private List<Row> rowList;
....
public List<Row> getRowList() {
return rowList;
...
When javabeans refer to a "property" it is something with a get() and a set()-method. It doesn't care what the internal storage of data is (if there even is one).
Thus a property "foo" has access methods getFoo() and setFoo(), what these methods do is irrelevant to the definition of the property.
http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html
That's defined by the JavaBeans naming conventions. The getter name will have "get" followed by the property name with the first letter capitalized.
A related question with more information
The JavaBeans Specification says that for a property
propertyName
there should be a getter methodgetPropertyName()
and/or a setter methodsetPropertyName()
.A property is defined by the only presence of the getter and setter methods and can also be a computed value. A instance variable on the object is not required.
The specification defines the capitalization rules for properties and getter/setter methods:
The method is in fact implemented as:
So:
name
is null, return it as suchname
has first two characters in caps, return it as such