Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

ClassInstanceCreation

Thread view: 
Dimitri Kurashvili - 21 Mar 2007 10:58 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.