NoCallOnStringLiteral
DRAFT

Misconception:

It’s not possible to invoke a method on a String literal. E.g., "Hi".length() does not work.

Incorrect

One cannot invoke methods on String literals

Correct

One can invoke methods on String literals

Correction
Here is what's right.

Wrong. A String literal denotes a String object. One can invoke methods on it like one can invoke methods on any String object. All the following are correct:

int a = "Hi".length();
int b = new String("Hey").length();
String s = "Ho";
int c = s.length();

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.