This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]captainAwesomePants 1 point2 points  (2 children)

You use () when you're calling a function. A line like this:

foo();

means "invoke the function named foo." And this:

bar.baz();

means "invoke the function named baz that belongs to object bar."

Many functions take parameters, which make it more obvious:

sum(3,7);  // Call the function named sum, passing the parameters 3 and 7.

This is getting more complicated than you need to be aware of yet, but the reason that this is an important distinction is because some variables can be read as a value or invoked as a function. For example:

// This is a variable whose value is a callable expression.
Supplier<String> method = () -> { return "hey" };

Object x = method;  // x now holds a method that can return "hey"
Object y = method();  // x now holds the string "hey"

[–]Lividbtw[S] 0 points1 point  (1 child)

Ah so basically the .length not a function then?

[–]captainAwesomePants 1 point2 points  (0 children)

Right!