Because they are used so commonly, strings can be created like primitives, yet they really are objects, thus you can write things like myStringVar.length(). It just makes it easier for the programmer. You have similar things in Ruby for arrays etc...
Si altas son las torres, el valor es alto - Alberti
Joined: Jun 16, 2006
Sorry, I'm still not understanding. Is the String class implementing an OO feature to enable it to act like a primitive or is the compiler doing some trick here that enables this special case?
There's no real function by that name, of course; instead Java takes a special action when it sees a quoted String literal. But those special actions are as if this made-up Java.getStringFromPoolOrCreateANewOne() function did something like:
So you see that Strings are always created with "new", just like any other object. It's just that there's a shorthand which hides this from you. It doesn't make Strings anything like primitives, though.