• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Operators

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Evening guys.

I'm a bit tired due to studying all day, and right now nothing makes sense to me. Could someone explain this?:



I thought that more or less any operation between 2 "integers" would result in an integer, assuming none of the integers are a long, in which case it all turns into a long. So multiplying 2 bytes like here (k and l) would result in an integer, being unassignable to our byte b.
This is also the case, if we do not use a compound operator: *= and only use an assignment operator =.

So, why does b *= k*l; compile when b = k*l; does not ?

Hope that was clear...

// Andreas
 
Saloon Keeper
Posts: 15524
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compound assignment operators perform silent casts.

a @= b

means the same as

a = (T) (a @ b)

where @ is an operator that has a compound assignment counterpart, and T is the type of a.
 
Andreas Svenkson
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks mate, I did not know that.

// Andreas
 
reply
    Bookmark Topic Watch Topic
  • New Topic