The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Access to anonymous inner classes

Posted by Ivan Villanueva on January 16, 2001 at 9:12 AM

I cannot access to the data and functions of a anonymous inner class like I acess to a normal innner class. I don't know why and I don't know how to do it.
Can anybody help me?

Hier is the example:

package delete;

abstract class C1 {
int numberC1 = 1 ;
}
class C2 {
int numberC2 = 2 ;
}

public class multipleI extends C1 {
static void takeC1(C1 c1) {}
static void takeC2(C2 c2) {}

int numberMultipleI = 3 ;

class C2b extends C2 {
int numberC2b = 4 ;
int function() { return numberC1 + numberC2 + numberMultipleI + numberC2b ; }
}
C2b c2bObject = new C2b() ;

C2 c2IAObject = new C2(){
int numberC2IA ;
{ numberC2IA = 5 ; }
int newFunctionInAnonymousInnerClass() { return numberC2IA ; }
} ;
public static void main (String args[]) {
multipleI m = new multipleI() ;
takeC1(m) ;
takeC2(m.c2bObject) ;
System.out.println(m.c2bObject.numberC2b) ;
System.out.println(m.c2bObject.function()) ;

// This doesn't work. Why ??!!
// System.out.println(m.c2IAObject.numberC2IA) ;
// System.out.println(m.c2IAObject.newFunctionInAnonymousInnerClass()) ;
// System.out.println(m.c2bObject.numberC1) ;
// System.out.println(m.c2bObject.numberMultipleI) ;
}
}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us