Why in Java can I instantiate an object with new without assigning that reference to a variable whereas if I do that with a string I get an error, isn't string also supposed to be an implicitly instantiated object?
new Persona();
"Hola mundo";
new Persona().decirAlgo();
"Hola mundo".toUpperCase();
Ok, in the first part according to what I have studied it works because what I am doing is calling a constructor function and it is not necessary to store what is returned in a variable since it is an invocation instruction but my question is here, ¿ Isn't the same thing supposed to happen with the string since when using the string an object is implicitly instantiated and therefore it would be calling a constructor method?
And in the other two examples I don't understand something either, I know that the invocation to the saySomething method works because the Constructor function returns a reference to that point in the execution of the program and therefore I can use the value returned by that expression but why if now I use the string to then call the method of the String class toUpperCase this works if when I try to use only the string "Hello world" in the previous statement it gives me an error because it should not work the same as when I call the constructor function using new in person?
That is, at that point where "Hello world" is not implicitly invoking a constructor and I do not get any reference and therefore I cannot invoke the method of the reference returned by the constructor method because the constructor method is not being calling but nevertheless if I use a string together with a method of the String class this works. Could someone explain to me exactly what happens?