Anonymous class - I don't know how to...
- From: kaja_love160@xxxxxxxxx
- Date: Thu, 28 Jun 2007 10:35:45 -0700
hello
1) Syntax for creating anonymous class:
new < superclass> ( <params> ) { <class definition> };
Example:
Object o = new Object() { public int anon = 20; };
The above statement creates an object of anonymous class and returns
a reference to it. But in order to use members declared in anonymous
class ( o.anon ), variable o would have to be of same type as
anonymous class. How do we make 'o' of same type, considering that
anonymous class has no name?
2)
If we declare class C inside method A(), then any local variable
( declared inside A() ) that will also be used inside class C, must be
declared final. Why? I assume there must be some valid reason for
that?
public void A ( final int i ) {
class C {
int u = i ;
}
}
thank you for your help
.
- Follow-Ups:
- Re: Anonymous class - I don't know how to...
- From: Mike Schilling
- Re: Anonymous class - I don't know how to...
- From: Roedy Green
- Re: Anonymous class - I don't know how to...
- From: Mark Space
- Re: Anonymous class - I don't know how to...
- From: Andreas Leitgeb
- Re: Anonymous class - I don't know how to...
- Prev by Date: Re: Dynamic reports from the Web using Java/Tomcat
- Next by Date: Re: Subclassing SSLSocket
- Previous by thread: Changing file Xtensions & importing
- Next by thread: Re: Anonymous class - I don't know how to...
- Index(es):
Relevant Pages
|