Why doesn't Java offer operator overloading?

前端 未结 17 2372
梦谈多话
梦谈多话 2020-11-22 07:38

Coming from C++ to Java, the obvious unanswered question is why didn\'t Java include operator overloading?

Isn\'t Complex a, b, c; a = b + c; much simpl

17条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 08:17

    The Java designers decided that operator overloading was more trouble than it was worth. Simple as that.

    In a language where every object variable is actually a reference, operator overloading gets the additional hazard of being quite illogical - to a C++ programmer at least. Compare the situation with C#'s == operator overloading and Object.Equals and Object.ReferenceEquals (or whatever it's called).

提交回复
热议问题