• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding null to Long

 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Car Class, I have plate Number (Long)
when I increment it I do :



what will happen if the PlateNumber is null?
isn't it like null + Long?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a NullPointerException when I tried it. What heppened when you tried it?

When you do this:

remember that autounboxing is happening in the background. So effectively what you are doing (pre JDK 1.5) is:

One of the reasons (in my opinion) autoboxing is best avoided.
[ June 18, 2008: Message edited by: Paul Sturrock ]
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sharon,

A NullPointerException will be thrown cause you are trying to add a value to 'null'. Never had considered a situation this kinds so I tried it out and thats what happened for me.

Cheers,
Raj.
 
Gopikrishna Kunisetty
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sharon,

If you have declared the data type of Plate number as long, then obviously its initial value will be '0' and not 'null'. So, if you try to increment, it will run without any issues.
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to Use Long in order to identify null values,
Well i guess the answer is

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic