Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Compile Error Vs runtime Error  RSS feed

 
Harikrishna Gorrepati
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?

 
Wouter Oet
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.
 
Arjun Srivastava
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?
 
Trivikram Kamat
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!