#What happens in the background when I override to String and Syso
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Also is there ressource on that, or like can I maybe, figure it out with debugger?
bc thats what the method does
if u look inside the println method it looks sth like this:
Syso, calls the toString?
void println(Object o) {
println(o.toString());
}
yes. theres no magic to it. it literally calls it
toString is a method defined in the all-father class Object
so any java class has this method
Ah, thats awesome.
but writing like Syso("This is a word" + a); // int a = 12;
what would happen then?
thats two parts
the compiler replaces ur string + with an actual method
"This is a word" + a is an expression which turns into a String
mhh
- is magic that is replaced by non-magic
Should I look it up in the vscode debugger?
for example (a bit simplified but u get the idea):
"abc" + foo is replaced by "abc".append(foo)
and that method is an ordinary java method that u can look up
which calls toString
append, calls toString?
yes
String append(Object o) {
return this.append(o.toString());
}
it looks sth like that
a method of the string class
there is a bit more happening under the hood, especially with + but u should get the idea
๐
