• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

boolean & Boolean - interchanable (where & where not)?

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above code compiles & gives output "true".
The API says public static boolean parseBoolean(String s)

I understand that because of Autoboxing feature, the code works fine.

Now can I say "We can use boolean and Boolean interchangably"? (Correct me if I am wrong)

What are exceptional case?
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raja,

Good question.
Small problem...

class BooleanTest{
Boolean b;

public void display(boolean b) { //Here null can't be converted to boolean
System.out.println("Boolean b value:"+b);
}
public static void main(String... a) {
new BooleanTest.display(b);

}
}
The above gives a NullPointerException bec'ze the Booleab b is initialized to null. and when we try to convert it into primitive boolean throws NPException.

Hope this example will help you.
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!