Reflection: How can you avoid the 'this' field when using getDeclaredFields()?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dan_Winterstein
Posted On:   Wednesday, May 24, 2006 05:17 AM

When using getDeclaredFields() to access a class's fields, on of the fields it returns is the 'this' field. That is, a field whose value is the object. This is throwing my program into an infinite loop, so I want to filter it out. What's the best way of doing so? It seems to always be last in the array returned by getDeclaredFields, so I could throw away the last value. Alternatively, it has names suchs as "this$0" which I could test for. Neither of these seem good solutions - they both depend upon non-api behaviour. Is there a 'proper' way to identify the 'this' field? Many thanks for any help, - Dan    More>>

When using getDeclaredFields() to access a class's fields, on of the fields it returns is the 'this' field. That is, a field whose value is the object.


This is throwing my program into an infinite loop, so I want to filter it out. What's the best way of doing so?


It seems to always be last in the array returned by getDeclaredFields, so I could throw away the last value.
Alternatively, it has names suchs as "this$0" which I could test for. Neither of these seem good solutions - they both depend upon non-api behaviour. Is there a 'proper' way to identify the 'this' field?


Many thanks for any help,

- Dan

   <<Less

Re: Reflection: How can you avoid the 'this' field when using getDeclaredFields()?

Posted By:   Byron_Tymvios  
Posted On:   Wednesday, May 24, 2006 05:48 AM


Can't you use the Field objects equals() method to test for equality with the Object you are interrogating?

About | Sitemap | Contact