Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » AST ClassInstanceCreationNode question
AST ClassInstanceCreationNode question [message #135180] Thu, 15 January 2004 17:12 Go to next message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

* Class instance creation expression AST node type.
*
* <pre>
* ClassInstanceCreation:
* [ Expression <b>.</b> ] <b>new</b> TypeName
* <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
* [ AnonymousClassDeclaration ]
* </pre>

How can a class creation expression have an "optionalExpression" on the
left hand side? I can't think of case where this is possible. It must be
rare. Could you please give me an example of:

(some expression).new AClass()

--
Thanks, Rich Kulp

Re: AST ClassInstanceCreationNode question [message #135280 is a reply to message #135180] Fri, 16 January 2004 02:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: markus_keller.ch.ibm.spam.protect.com

This is a Java language question and not specific to eclipse.

From the Java Language Specification 2.0:

15.9 Class Instance Creation Expressions
[..]
ClassInstanceCreationExpression:
new ClassOrInterfaceType ( ArgumentListopt ) ClassBodyopt
Primary.new Identifier ( ArgumentListopt ) ClassBodyopt
[..]
Qualified class instance creation expressions begin with a Primary. A quali-
fied class instance creation expression enables the creation of instances of
inner member classes and their anonymous subclasses.
[..]

In sane code, you probably won't find that construct. Here's an example:

public class A {
public class B {
void foo() {
System.out.println("A.this = " + A.this);
}
}
public static void main(String args[]) {
new A().new B().foo();
}
}

Markus


Rich Kulp wrote:

> * Class instance creation expression AST node type.
> *
> * <pre>
> * ClassInstanceCreation:
> * [ Expression <b>.</b> ] <b>new</b> TypeName
> * <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
> * [ AnonymousClassDeclaration ]
> * </pre>
>
> How can a class creation expression have an "optionalExpression" on the
> left hand side? I can't think of case where this is possible. It must be
> rare. Could you please give me an example of:
>
> (some expression).new AClass()
>
Re: AST ClassInstanceCreationNode question [message #135571 is a reply to message #135180] Sat, 17 January 2004 11:52 Go to previous message
Eclipse UserFriend
Originally posted by: sandipchitale.comcast.net

When creating non-static inner classes you need a 'this' context of
out object. Normally it is the implicit outer instance. However by using

(some expression yielding outer class instance).new NonStaticInnerClass()

you can provide the context of outer class. Is is sometimes useful in
creating non-static inner class in a static method of inner class.

Remember:

new NonStaticInnerClass();

is really

this. new NonStaticInnerClass();

HTH,
sandip

"Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message news:bu736i$rh1$1@eclipse.org...
> * Class instance creation expression AST node type.
> *
> * <pre>
> * ClassInstanceCreation:
> * [ Expression <b>.</b> ] <b>new</b> TypeName
> * <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
> * [ AnonymousClassDeclaration ]
> * </pre>
>
> How can a class creation expression have an "optionalExpression" on the
> left hand side? I can't think of case where this is possible. It must be
> rare. Could you please give me an example of:
>
> (some expression).new AClass()
>
> --
> Thanks, Rich Kulp
> 
>
Previous Topic:Problem using Eclipse with SourceForge CVS repository...
Next Topic:Postings
Goto Forum:
  


Current Time: Tue Jul 22 14:44:58 EDT 2025

Powered by FUDForum. Page generated in 0.03305 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top