File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes + 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 "+ operator overloading" Watch "+ operator overloading" New topic
Author

+ operator overloading

Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Hello experts,

i have this code '1' + 1 which I think that translates to (int)'1' + 1 = 49 + 1 = 50 . So I would say that number +(char, number) is a signature on one hand, and another one would be String +(String,number) for this situation "1" + 1 = "11".

can anyone please tell me where I could find documentation about the + method ?

thank you for all your help.

kind regards,
radu
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Marius Constantin wrote:
i have this code '1' + 1 which I think that translates to (int)'1' + 1 = 49 + 1 = 50 . So I would say that number +(char, number) is a signature on one hand, and another one would be String +(String,number) for this situation "1" + 1 = "11".

can anyone please tell me where I could find documentation about the + method ?



Java Language Specification, Section 15.18.1.

Basically, if either (or both) operands is a string, then it is a string concat. Otherwise, it is not.

Henry
Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Henry Wong wrote:
Marius Constantin wrote:
i have this code '1' + 1 which I think that translates to (int)'1' + 1 = 49 + 1 = 50 . So I would say that number +(char, number) is a signature on one hand, and another one would be String +(String,number) for this situation "1" + 1 = "11".

can anyone please tell me where I could find documentation about the + method ?



Java Language Specification, Section 15.18.1.

Basically, if either (or both) operands is a string, then it is a string concat. Otherwise, it is not.

Henry


Thank you very much Henry! Can you please point out a link the he lang specs, where I could find the section mentioned ?

thank you,
radu
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Marius Constantin wrote:
Thank you very much Henry! Can you please point out a link the he lang specs, where I could find the section mentioned ?


http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html
Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Henry Wong wrote:
Marius Constantin wrote:
Thank you very much Henry! Can you please point out a link the he lang specs, where I could find the section mentioned ?


http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html


Thank you very much!
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

ah, that hard to read JLS. i have kind of been looking for it. thanks for the link. i wonder if they have a downloadable version.


SCJP
Visit my download page
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Randall Twede wrote:ah, that hard to read JLS. i have kind of been looking for it. thanks for the link. i wonder if they have a downloadable version.


http://java.sun.com/docs/books/jls/
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

thanks henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: + operator overloading