harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Varlamov" <alexey.v.varla...@gmail.com>
Subject Re: [classlib][lang] Is it possible to new an object without invoking any constructor?
Date Thu, 15 Nov 2007 05:21:18 GMT
2007/11/15, Nathan Beyer <ndbeyer@apache.org>:
> Do you mean this?
>
> class MyObject {
>  String field;
>  MyObject(){
>      super();
>  }
> }

or simply "class MyObject { String field; }" - just as you wanted, no
any constructor ;)

>
> 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.
>
> 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
> invoked.
>
> -Nathan
>
> On Nov 14, 2007 11:58 PM, Andrew Zhang <zhanghuangzhu@gmail.com> 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/
> >
>

Mime
View raw message