• Post Reply Bookmark Topic Watch Topic
  • New Topic

check for object emptiness  RSS feed

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a scenario where in the object is constructed but sometimes it is not initialized (i.e. its instance variables are not set) and passed on.
The instance variables are proper object types like String, BigDecimal etc and not using java primitives.

Now I want to figure out a way to determine if the object in question is empty.How can I go about this.

Thanks,

M

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you have access to the members. you could write some kind of validateObject() method that you pass your object into. It would then have a lot of

if (object.a == null)

type statements in it.

This is not a very elegant solution, but it would work. a better question is why do you get an object that is not completely created? Can you modify the contsrutcer?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. Change the constructor to throw an exception if you try to create an "empty" object; then the object will not be created in the first place.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!