Why doesn't Java offer operator overloading?

前端 未结 17 2363
梦谈多话
梦谈多话 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:37

    Saying that operator overloading leads to logical errors of type that operator does not match the operation logic, it's like saying nothing. The same type of error will occur if function name is inappropriate for operation logic - so what's the solution: drop the ability of function usage!? This is a comical answer - "Inappropriate for operation logic", every parameter name, every class, function or whatever can be logicly inappropriate. I think that this option should be available in respectable programing language, and those that think that it's unsafe - hey no bothy says you have to use it. Lets take the C#. They drooped the pointers but hey - there is 'unsafe code' statement - program as you like on your own risk.

提交回复
热议问题