?
Solved

Is there a way to zero-fill an Object?

Posted on 2004-11-02
7
Medium Priority
?
206 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:ycomp
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12477148
I think it is not possible
but let me try
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12477170
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12477189
add a destructor to ur class

      protected void finalize()
      {
        a = 0;
        B = null;
     
      }
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:petmagdy
ID: 12477208
ahhh sorryy i got it, sorry for my last comment
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12477262
I believe   your clear method is only final option
0
 
LVL 13

Accepted Solution

by:
petmagdy earned 2000 total points
ID: 12477277
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
 

Author Comment

by:ycomp
ID: 12477284
thanks guys. sounds like the answer is that it is more trouble than it is worth. But thanks for answering.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question