Every single time I deal with this, it punches me in the face. I love it because its cool, I hate it because I always forget.
ArrayList myArray = new ArrayList();
myArray.add("Mutemath is coming back to KC this fall!");
out.write(myArray.size()); // size() = 1
Note the parentheses that follow the
size() method: This implies that it is really a function and not a simple property of the object. Most properties of Java objects are private, which are then accessed through public functions, such as
length() and not
size() as is the syntax for its java counterpart.
var l = myArray.length();
alert(l + "!"); // Fiesta. We are really excited about the length of the array.
length is a property, and not a function. It is accessed only without the parentheses, as no function exists by that name.
var l = myArray.length;
This has happened to me more times than I care to admit.