Java不能重载任何运算符.为什么? [英] Java cannot overload any operators. Why?
问题描述
可能重复:
Java运算符重载
Possible Duplicate:
Java operator overload
在c ++中,我们可以执行运算符重载.但是Java还是一种面向对象的语言.那么,为什么Java不支持重载呢?
In c++, we can perform the operator overloading. But Java is also a Object oriented language. So why java doesn't support overloading?
推荐答案
实际上,它确实支持运算符重载……这是非常有限的,仅内置的.例如,除了常用的运算法则外,String的"+"也已重载.
Actually, it does support operator overloading... of a very limited, built-in only nature. For instance "+" is overloaded for String's in addition to the usual arithmetic.
当然,大多数人都想知道Java为什么不支持用户定义的运算符重载. :-)最简单的答案似乎是,当时的Java创建者没有看到任何干净的方法将其添加到语言中,而不会在过程中使Java混乱(如C ++).
Of course, most people want to know why Java does not support user-defined operator overloading. :-) The simplest answer seems to be that the Java creators did not, at the time, see any clean way to add it to the language without making Java a mess (like C++) in the process.
这篇关于Java不能重载任何运算符.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!