I've seen some legacy code that uses length
property on some objects and others that uses length()
method. Currently I'm working with a NodeList
from the org.w3c.dom
package and I found that it have the getLength()
method to get the numbers of elements.
My Question is how as Java developer I can know how to determine when to use length
, length()
, size()
, getLength()
? obviously it depends of the object type and the API is there for read... but the point is how the Java Development select which of that implements in their classes.
Note: In the Question When to use .length vs .length() Makoto answer's indicates that .length
is a property on arrays. That isn't a method call, and length()
is a method call on String. But, why is the reason? why not use ever a method or ever a property for maintain the consistency around all the API.