0

If Java does not allow operator overloading, how are operators like - or * able to work with various data types such as doing 5 + 5 or 5 * 5 in some code in Java. Does that mean these operators are overloaded internally in the background in Java, but the user cannot overload them?

Additionally, it is said how the + operator can be used to concatenate Strings by the compiler if String objects are used. Would that not mean there is some overloading happening in the background by language design since the + sign is being replace with some definition to concatenate Strings?

  • Unlike C++ (and some other languages), it is _not_ possible to overload the basic arithmetic oprerators in Java. – Tim Biegeleisen Nov 12 '20 at 08:16
  • 4
    Does this answer your question? [Operator overloading in Java](https://stackoverflow.com/questions/1686699/operator-overloading-in-java) – lorenzozane Nov 12 '20 at 08:26
  • Even ancient programming languages like FORTRAN had different implementations for the arithmetic operators, applying to integers, floats and doubles. You might call that a kind of overloading, but generally the term is only used if that feature is available to the user. – Ralf Kleberhoff Nov 12 '20 at 09:15

0 Answers0