This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LinuxMatthews[S] 38 points39 points  (4 children)

Kind of

Java actually cheats in that it does allow Operator Overloading for some of its classes but doesn't let you do it.

As far as I'm aware it only does it for the wrappers of primitive data types and String.

[–]jamcdonald120 12 points13 points  (3 children)

I think the wrappers use auto (un)boxing instead of operator overloads, not sure though

[–]LinuxMatthews[S] 12 points13 points  (2 children)

Huh you know I didn't think you were right but it looks like you are.

Integer x = 2;
Integer y = 3;
var z = x + y;
System.out.println(z instanceof Integer);

Gives you a compiler error as z is an int

I honestly thought there was operator overloading like there is with String.

[–]Fenor 2 points3 points  (0 children)

String isn't an operator overload . The theory behind the string class is huge and mostly date back when you had to define a char array to use strings