On Nov 15, 2007 1:07 PM, Nathan Beyer <[EMAIL PROTECTED]> wrote:
> Do you mean this?
>
> class MyObject {
> String field;
> MyObject(){
> super();
> }
> }
>
> MyObject mo = new MyObject();
>
> With regard to fields being in their default state, that's what
> happens by default. The only thing that changes this is if you inline
> field assigment with the declaration or assign the fields in the
> constructor.
Hi Nathan,
I want an object with all null values for all reference fields, and default
value(0/false) for primitive fields, even there's a constructor:
public class MyObject {
int i;
String s;
B b;
MyObject() { i = 100; s = "hello"; b= new B(); }
}
I want to have a MyObject myObject whose i = 0, s = null and b = null.
Yes, it's very like the initial state of de-serialized. What I have is the
class definition (e.g class MyObject above), and I want to "new" an instance
with all null/0 value of MyObject.class by some way. Is it possible? Thanks!
>
>
> As for creating a new instance without calling a constructor, that's
> what happens when an instance of something is de-serialized. No
> constructor is called; just the readObject() and related methods are
But I don't have an FileInputStream instance...
>
> invoked.
>
> -Nathan
>
> On Nov 14, 2007 11:58 PM, Andrew Zhang <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Is it possible to new an object without invoking any constructor? I know
> the
> > question is a bit weird. What I want is to create an object with all
> > null/default value for its fields.
> > Reseting all fields to null by reflection is a possible solution, but is
> > there any existing special method (no matter it's low level or Harmony
> > specific) which can achieve this goal?
> > Thanks!
> >
> >
> > --
> > Best regards,
> > Andrew Zhang
> >
> > http://zhanghuangzhu.blogspot.com/
> >
>
--
Best regards,
Andrew Zhang
http://zhanghuangzhu.blogspot.com/