can somebody explain me why it's possible to do:
String s = "foo";
how is this possible without operator overloading (in that case the "=")
I'm from a C++ background so that explains...
In this case there is no overloading. The java piece that differs from C++ is the definition of "" - The java compiler converts anything in "" into a java.lang.string and so is a simple assignment in your example. In C++ the compiler converts "" into a char const * and so needs to have a conversion from char const* to std::string.
This assigns a simple literal of type String to s
In Java Strings are immutable, if you need to define a constant value you would use the final
keyword.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With