Is there a way to zero-fill an Object?

Hi,

I'm pooling objects and I keep on adding properties once in a while to the Object. I was thinking it would be easier (if java lets you do this) to simply zero-write the object's properties instead of remembering to add each new property to some clear() method.

e.g.

Class PooledThing {
  int A = 0;
  String B = null;
}

instead of having to write:

void clear() {
  a = 0;
  B = null;
}

and calling PooledThing.clear() when the object is released from the pool, is there a way to call PooledThing.wipe() or something like that that will just zero-fill everything making it a =0, B=null ?

I suspect the answer is no but I want to ask you java gurus out there.
ycompAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sudhakar_koundinyaCommented:
I think it is not possible
but let me try
0
sudhakar_koundinyaCommented:
Class PooledThing {
  int A[] =new int[1];
  String B[] = new String[1];
}

If  This is a model

Arrays.fill(pooledThing.a,0);
Arrays.fill(pooledThing.b,null);
0
petmagdyCommented:
add a destructor to ur class

      protected void finalize()
      {
        a = 0;
        B = null;
     
      }
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

petmagdyCommented:
ahhh sorryy i got it, sorry for my last comment
0
sudhakar_koundinyaCommented:
I believe   your clear method is only final option
0
petmagdyCommented:
but u can do something complex with java.lang.reflection, by creating a base that is given An object will iteriate over it fields and if if simple Data type set to Zero or i based on Object set to null
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ycompAuthor Commented:
thanks guys. sounds like the answer is that it is more trouble than it is worth. But thanks for answering.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.