DRAFT
CallOnPrimitive
Misconception:
It is possible to call a method on values of primitive types.
Incorrect
One can invoke a method on primitive values
Correct
CorrectionHere is what's right.
Here is what's right.
Methods can only be called on objects. That is, o.m()
works only if o
is of a reference type.
Integer i = ...;
String s = i.toString(); // ok
int i = ...;
String s = i.toString(); // not possible in Java
Examples
public static int f(int x) {
...
}
int v = ...;
v.f; // should be f(v)
(v-1).f // should be f(v-1)
Language
Java