$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #241

Which fix removes the bug?

String name = "Ada";
System.out.println(name.length); // compile error
  1. Call it as a method: name.length()
  2. Use the size field: name.size
  3. Cast first: ((Object) name).length
  4. Use String.length(name) instead
For a String, length is a method, not a field. Arrays have a length field, which is why the two get mixed up.
Play Problem Solving ▸