Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Operator Overloading...

 
vijay Krishnan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

why doesn't java support operator overloading...?

i need the clear idea about this please anyone
explain this in detail...


Thank you

regards,
Vijay
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15208
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some info:

Bug ID: 4905919 RFE: Operator overloading
Operator Overloading Considered Harmful
The Java Language Environment - Features Removed from C and C++

The bottom line is that the people who invented Java thought that operator overloading makes code too complicated and isn't really necessary.

Use Google to find more info.
 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not quite true that Java doesn't support operator overloading; the "+" operator is overloaded so it acts as addition most of the time, but in the case of Strings represents concatenation.

You can use | for "logical OR" with two boolean expressions and for "bitwise OR" with two integer numbers, similarly with & and ^, but you might not call that overloading.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15208
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right, some operators are overloaded such as "+" for strings, but these are special cases - the compiler handles them specially.

Java does not have user-defined operator overloading; you cannot overload operators yourself.
 
vijay Krishnan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i know that eventhough i need some clarifications about this that is why i posting this question.

thank you guys for explaing this concept to me.
thank you so much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic