• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Switch with wrappers

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to everybody

Given the following method

what is the result of calling the method test with a null value ?

What are the rules for this case so the result is: "Case Default" gets printed to the console but not NullPointerException thrown by the method at runtime

Thanks in advance
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what didi you use to run the program...I only get a NullPointerException.
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Switch can only use constant expression, so you should define that null as constant expression..
We can't check the case as below :


if you want to your code execute default block, i think you should assign whichever integer constant for its value that doesn't mentioned at case conditions..

so, your code should be :


Result : Case Default

Please correct me if i'm wrong..

Thanks,,
 
Natallia Bahlai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the result is NPE. Thanks for replies. I understand this issue.
 
Trust God, but always tether your camel... to this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic