• 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

practice example for young tigers: mixing equailty and autoboxing

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This all started with an innocent question of a mock exam, but when i added some autoboxing features, here's what happend...
So young Tigers, can you spot which line will be printed, and which will (individually) cause a compile-errror or runtime-error?
Enjoy, Renaud

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if (c.equals(d)) System.out.println("c and d are equals");
if (c.equals(e)) System.out.println("c and e are equals");
c is primitive! (compile time error)!

if (a.intValue() == ((Long)b).longValue()) System.out.println("EQ ab");
Invalid cast at compile-time.

I think most others will print, oder?
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<my-answer excuses-for-being-wrong="tired, beer, it's Sunday">
b == e
a and b are equals
a and c are equals
a and e are equals
b and c are equals
b and e are equals
c and e are equals
java.lang.ClassCastException
</my-answer>

Is your "innocent question" related to the apparant obscure output of the following?

[ February 06, 2005: Message edited by: Tony Morris ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic