Bindings created for Anonymous Classes: how can I know if they represent the e same anonymous class? [message #646183] |
Wed, 22 December 2010 15:12 |
Joan Robert Messages: 16 Registered: December 2010 |
Junior Member |
|
|
Hi, in the code snippet below, in the 2nd line, I'm creating a new anonymous class, that has the following binding key: 'Ltestepackage/AnonymousClasses$328;'
1. public static void main(String[] args) {
2. Ball b = new Ball() {
3. public void hit() {
4. System.out.println("You hit it!");
5. }
6. };
7. b.hit();
8. }
interface Ball {
void hit();
}
In the 7th line, b.hit() references a method implementation of that anonymous class, however, the binding of the class that declares that method has the key: 'Ltestepackage/AnonymousClasses$Ball;' (it's different).
Is there any way to know which anonymous class I am making a reference to? That is, if two bindings represent the same anonymous class.
Since the key of the binding doesn't seem to allow me that, is there an alternative way?
[Updated on: Wed, 22 December 2010 15:13] Report message to a moderator
|
|
|
Re: Bindings created for Anonymous Classes: how can I know if they represent the e same anonymous cl [message #646226 is a reply to message #646183] |
Wed, 22 December 2010 18:46 |
Deepak Azad Messages: 543 Registered: July 2009 |
Senior Member |
|
|
On 12/22/2010 8:42 PM, Joan Robert wrote:
> Hi, in the code snippet below, in the 2nd line, I'm creating a new
> anonymous class, that has the following binding key:
> 'Ltestepackage/AnonymousClasses$328;'
>
> 1. public static void main(String[] args) {
> 2. Ball b = new Ball() {
> 3. public void hit() {
> 4. System.out.println("You hit it!");
> 5. }
> 6. };
> 7. b.hit();
> 8. }
>
> interface Ball {
> void hit();
> }
>
> In the 7th line, b.hit() references a method implementation of that
> anonymous class, however, the binding of the class that declares that
> method has the key: KEY: 'Ltestepackage/AnonymousClasses$Ball;' (it's
> different).
The method is *declared* in the interface, and the binding is for the
interface, not the anonymous class.
>
> Is there any way to know which anonymous class I am making a reference
> to? That is, if two bindings represent the same anonymous class.
The variable is of type Ball, it is only at runtime that you can check
the type of the actual object.
> Since the key of the binding doesn't seem to allow me that, is there an
> alternative way?
>
>
I am not sure what you want to achieve.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03095 seconds