DRAFT
NoCallOnStringLiteral
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
CorrectionHere is what's right.
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();
Language
Java