• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking for Null in Boolean-pls validate  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public Boolean getvalue()
{

}

if (getValue() == null) {
System.out.println("Null value retunred)
}

Is this correct?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your getvalue method does not return anything:



This seems to be in the spirit of what you are attempting.

[ December 04, 2005: Message edited by: Darren Horsman ]
[ December 04, 2005: Message edited by: Darren Horsman ]
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to verify something like this is to write some test code...

Yes, you could also use == to test for null; but typically you're interested in doing something with the reference if it's not null, in which case using != is easier to read.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well u r fuction doesnt do any thing.it does return a value as well.
Write return null; in the fuction and the rest would work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!