• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About Operator Overloading...

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79275
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I am displeased. You are no longer allowed to read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic