This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile Error Vs runtime Error

 
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
Saloon Keeper
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic