Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

cast

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please any body can tell me what is the different between the following tow cast the first one give you c/r and the second do the implicit cast ???
byte b=1;
long l=1000;
b =b +l;
2:

byte b=1;
long l=1000;
b += l;
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll try to help you to help yourself.
Look at the first part:
Ask your self "what is the type of the result b+l?", then look at the type of b .
What must you do to force the compiler to assign that result to b ?
Now look at the second part.
What does b +=l mean?
Read the Java Language Specification (section) 15.26.2 Compound Assignment Operators.
What does the compiler do for you in this case?
The specification says that is equivalent to . What is that (T)?
Tell us what you find out.
Best wishes
-Barry
[ August 08, 2002: Message edited by: Barry Gaunt ]
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry ,
The Java programming language uses the rule Always true when use implicit cast to the type of the left hand operand
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in the first part you must do the cast.
In the second part the compiler does it for you.
That to me is the difference between the two code
examples.
Agree?
-Barry
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with you this rule I can find logical explanation except that you said and Always (true when use implicit cast to the type of the left hand operand)
Thanks Barry
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic