I have spent hours researching this, and I'm still very confused.
I, like many others, searched this on Google and found this SO thread.
However, recently, a student in one of my programming courses told me that this wasn't true, and in fact, the instructor verified it. Hell, the entire class heard it, and no one contested him. He offered this link from Java.net as proof.
I said to him immediately, "That looks like JavaScript," but he pointed to this section:
class User {
List roles;
User() {
roles = new List();
}
operator +(Role newRole) {
this.roles.add(newRole);
}
}
main() {
User alice = new User();
Role adminUser = new Role("TIMESHEET_ADMIN", 3);
alice + adminUser;
print(alice.roles.length);
}
and told me that it was indeed Java. I, having no experience in JS couldn't tell, and he got away (for now), but I tried putting this into my IDE (IntelliJ), and I was assaulted by compiler errors. I didn't even know where to begin with fixing them, but the main thing was the cannot resolve symbol "operator"
.
I'm not looking here for any discussion on Java's built-in operator overloading, I am looking for a definitive answer on whether or not users in Java can overload operators themselves.