• 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: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Source: Sun Certified Programmer for Java 6 Study Guide
Pages: 313/314
Authors: Kathy Sierra & Bert Bates




The above code compiles and runs fine,
Im simply asking for a brief explanation
on how the if statement resulted as "true"
bearing in mind that Long and float are
diferrent Types.
Thank you for your help.

 
Ranch Hand
Posts: 152
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ikpefua,
At line no: 7 in your code. the JVM will automatically do widening conversion of long to float and will compare both the values.
hence the println prints true.
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SearchFirst, this is discussed recently.

And this is called Numeric promotion, have a look on this
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pravin Shirke wrote:hi Ikpefua,
At line no: 7 in your code. the JVM will automatically do widening conversion of long to float and will compare both the values.
hence the println prints true.



Hi Pravin, thanks a lot for your explanation.
 
reply
    Bookmark Topic Watch Topic
  • New Topic