Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Compile Error Vs runtime Error

 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why I am getting one error in loop during compile time and similar error during Runtime in the other loop?

 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all please QuoteYourSources.

The compile time error is because you're trying to compare a null (reference to nothing) to a primitive boolean. That can't be done. It's like comparing apples to your left shoe. They are completely different.

The NullPointerException is caused by auto-unboxing of the second value of the Boolean array. Note that it is a wrapper Boolean not a primitive thus it's default value is null.
 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Wouter Oet wrote:The compile time error is because you're trying to compare a null (reference to nothing) to a primitive boolean. That can't be done. It's like comparing apples to your left shoe. They are completely different.
The NullPointerException is caused by auto-unboxing of the second value of the Boolean array. Note that it is a wrapper Boolean not a primitive thus it's default value is null.



this time it works fine*
as null is comparable to object,also wrapper classes,is it so?
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Arjun Srivastava wrote:
this time it works fine*
as null is comparable to object,also wrapper classes,is it so?



Yeah, it must be the correct reason.
An Object can be given a null reference. So, it can be compared to a null.
And all classes are derived from Object class in Java (except Object class of course). So, instances of Wrapper classes can be compared to that of Object class.
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic