Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

+ operator overloading

 
Marius Constantin
Ranch Hand
Posts: 62
Java Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
Java Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
Java Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic