Below is a definition of ClassInstanceCreation as it is defined in
Eclipse JDT.
I'm confused about what is a first expression (i mark it with question
sign).
========================================
ClassInstanceCreation:
[ Expression . ] < - - - - - - - - - - - - ?
new [ < Type { , Type } > ]
Type ( [ Expression { , Expression } ] )
[ AnonymousClassDeclaration ]
========================================
So i can write something like this:
========================================
SomeExpression.new String("mystring")
========================================
what may be SomeExpression that the code above can compile?
==
Thanks, Dimitri
Simon - 21 Mar 2007 11:16 GMT
> So i can write something like this:
>
[quoted text clipped - 3 lines]
>
> what may be SomeExpression that the code above can compile?
This is in fact a rarely used construction. If a class A declares an inner class
I (that is not static), and you have an object a of type A, you can in fact write
A.I i = a.new I();
This is necessary, since the instance of the inner class needs a reference to an
instance of the enclosing class A.
Cheers,
Simon
Dimitri Kurashvili - 21 Mar 2007 13:58 GMT
this is why i could not instantinate inner classes without declaring
them static!
> > So i can write something like this:
> >
[quoted text clipped - 14 lines]
> Cheers,
> Simon
Lew - 21 Mar 2007 19:56 GMT
Please do not top-post.
> this is why i could not instantinate inner classes without declaring
> them static!
If you declare them static, they aren't inner classes.
-- Lew
Tom Hawtin - 21 Mar 2007 11:21 GMT
> ClassInstanceCreation:
> [ Expression . ] < - - - - - - - - - - - - ?
> new [ < Type { , Type } > ]
> Type ( [ Expression { , Expression } ] )
> [ AnonymousClassDeclaration ]
> SomeExpression.new String("mystring")
> ========================================
>
> what may be SomeExpression that the code above can compile?
The syntax is for specifying the outer class instance when constructing
an inner class. It's exceptionally rare to require anything other than
the implicit this (if you call the constructor from an inner class, it
may be an outer this rather than the inner most this). I would stay well
away from attempting to use that particular feature.
Tom Hawtin
Dimitri Kurashvili - 21 Mar 2007 11:54 GMT
Thanks a lot Simon and Tom.
It was really usefull for me.
pimpolhott31@hotmail.com - 21 Mar 2007 17:05 GMT
> Thanks a lot Simon and Tom.
> It was really usefull for me.