This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on primitive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on primitive" Watch "Question on primitive" New topic
Author

Question on primitive

Thiyagarajan Kamala
Ranch Hand

Joined: Mar 16, 2003
Posts: 30
short s1=6;
s1+=20000;

if I rewrite this to
short s1=6;
s1=s1+20000;

Compile complains ...Can someone explain?.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
This will work...


The problem is that without the cast you try to assign an int to a short, which will make the compiler choke.

Using the short assignment (+=) I think the compiler does that for you, but I'm not 100% sure.


JDBCSupport - An easy to use, light-weight JDBC framework -
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9400
    
  20

Read this...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Thiyagarajan Kamala
Ranch Hand

Joined: Mar 16, 2003
Posts: 30
Thanks Ankit.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9400
    
  20

Sebastian was also right, so thanks to him too ...
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Ankit Garg wrote:Sebastian was also right, so thanks to him too ...


sweet
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9400
    
  20

Sebastian Janisch wrote:sweet


Sugar .......... Ooops, I forgot this is not the word-association thread
Thiyagarajan Kamala
Ranch Hand

Joined: Mar 16, 2003
Posts: 30
my bad ...Thanks to both of you...If i get this question in exam I will remember both of you.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Question on primitive
 
It's not a secret anymore!