J
jkj2000
Hi everyone,
Bit of a newbie question here I guess. I'm reading a code snippet
that instantiates a class inside another, but outside the
constructor. It looks like this:
public class MyClass
{
private ProxyClass default =
new ProxyClass()
{
public MyComponent proxy()
{ //return something here}
}
//...
// other methods defined here for MyClass
//..
}
The ProxyClass above is declared and instantiated at the same time,
but instantiation takes place outside a constructor or any other
method of MyComponent. (ProxyClass is defined as an interface.)
I've always assumed the new keyword had to be used within a method,
constructor or otherwise. Maybe it's different here because the code
is creating an anonymous inner class --please correct me if I'm wrong.
In any event, when does the instantiation take place? At some point
after the MyClass default constructor runs? I'm mainly trying to get
the sequence of events correct. Thanks very much....
Bit of a newbie question here I guess. I'm reading a code snippet
that instantiates a class inside another, but outside the
constructor. It looks like this:
public class MyClass
{
private ProxyClass default =
new ProxyClass()
{
public MyComponent proxy()
{ //return something here}
}
//...
// other methods defined here for MyClass
//..
}
The ProxyClass above is declared and instantiated at the same time,
but instantiation takes place outside a constructor or any other
method of MyComponent. (ProxyClass is defined as an interface.)
I've always assumed the new keyword had to be used within a method,
constructor or otherwise. Maybe it's different here because the code
is creating an anonymous inner class --please correct me if I'm wrong.
In any event, when does the instantiation take place? At some point
after the MyClass default constructor runs? I'm mainly trying to get
the sequence of events correct. Thanks very much....