Forums Register Login

Anonymous Inner Class

+Pie Number of slices to send: Send
class test1 {
public void method1() {}
}

class test2 {
test1 p = new test1() {
public void method1() {}
public void method2() {} //where method2 goes ??
};
}

class access {
void access(){
test1 t = new test1();
t.method1(); //perfect i can access to method1
//but HOW can i access to anonymous method2 ??
}
}
+Pie Number of slices to send: Send
Can't be done (except by using reflection.) The only methods you can access normally are those accessible through the type of the reference variable.
+Pie Number of slices to send: Send
ok, so the method2() is lost in the heap with no reference ?

what is reflection ?

thanks !
+Pie Number of slices to send: Send
 

Originally posted by podonga poron:
ok, so the method2() is lost in the heap with no reference ?



No, a method is not a separate object, so it's not that; it's just that there's no Java syntax to refer to that method.

"Reflection" is a kind of magic way to create objects and call methods based only on Strings containing their names; it's implemented in the java.lang.reflect package. It's not used much in normal programming, but it's used a lot by IDEs, Web containers, JavaBean containers, etc.
I can't take it! You are too smart for me! Here is the tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 817 times.
Similar Threads
static methods
How a method on stack knows that to which object on heap it is connected?
About Overridden II (a Mock Question question...)
which can method2 can access without reference?
need a clarification in synchronization
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:41:25.