*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38025
    
  22
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: 14074
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Operator Overloading...
 
Similar Threads
How to add two Number?
Doubt.......null?
Advice on BigDecimal vs. double
operator overloading
Typical Overriding and Overloading Examples