• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Operator Overloading in java ?

 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know java language does not provide operator overloading facility for developers ...

But whether java language internally using operator overloading facility (such as String concatination using + operator )??

Any one have idea ....
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If String catenation with the + operator isn't operator overloading, what is it?

Other overloaded operators are & | ^. Some people say ++ and -- are overloaded, too. Search for operator/operators overloading/overload/overloaded; this question is asked regularly.
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If String catenation with the + operator isn't operator overloading, what is it?

yes then shall i confirm that ....
 
Avishkar Nikale
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijin,

Operator overloading makes easy to read code
but can be replaced with methods/functions which do the same thing.

So I should say "nice to have" but not needed.

So "+" overloading for String is given by Java at compile time
but who knows the byte code might still call the concat() method if one these is a reference
& make a bigger literal if both are literals.

Since String will require concatenation the most of all Objects which can be created in
a program "+" has a better readability & can be used.

But for custom or any other objects, nope there isn't any (till now).



 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avishkar Nikale wrote:.
Thanks for sharing info Avishkar
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijin, it would be much better/understandable if you write your comments outside the 'quote' block.
'quote' blocks are just to indicate - to which part of the previous post(s) you are commenting to. If your comments are inside some 'quote' block , then people reading the posts may possibly get confused.
If you have nothing to quote at all, a better option is clicking 'Post Reply' button at the bottom.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avishkar Nikale wrote:. . . Operator overloading makes easy to read code . . .
Does it really? I am writing a parser which has to distinguish - in 1 - 2 from - in -123 from - in 1.23e-45. I am not at all convinced that lots of overloaded operators make your code easy to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic