GeeCON Prague 2014*
The moose likes Java in General and the fly likes About Operator Overloading... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "About Operator Overloading..." Watch "About Operator Overloading..." New topic
Author

About Operator Overloading...

vijay Krishnan
Greenhorn

Joined: Jul 27, 2006
Posts: 14
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

Joined: Aug 16, 2005
Posts: 14194
    
  20

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39070
    
  23
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

Joined: Aug 16, 2005
Posts: 14194
    
  20

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

Joined: Jul 27, 2006
Posts: 14
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.
 
GeeCON Prague 2014
 
subject: About Operator Overloading...