*
The moose likes Beginning Java and the fly likes reflexion and enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reflexion and enum" Watch "reflexion and enum" New topic
Author

reflexion and enum

mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
hi

i use this code



getGlass return an enum

is there a way to do that with reflexion?

thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

is there a way to do that with reflexion?


Not sure what you are asking. Can you elaborate? enums are just objects, so the reflection library should work for them too.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
this line of code is in a class X who extends Y



this class Y have



Glass is an enum

so my question is how to be able to do the same thing then



but with reflexion?

i tried



but i'm not able to access the field (tickness)

any idea?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

mark smith wrote:
but i'm not able to access the field (tickness)

any idea?


Try...




BTW, if you know the exact method to execute, and the exact field to get, why do you need reflection? The way you are doing it now is much easier than using reflection.

Henry
mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 246
thanks Henry Wong that work...

the method can change... not the field...
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

mark smith wrote:thanks Henry Wong that work...

the method can change... not the field...


If the field doesn't change, then there is no reason to use reflection to get it... you can simply cast and dereference it.



Henry
 
jQuery in Action, 2nd edition
 
subject: reflexion and enum
 
Similar Threads
How disable FocusTraversalPolicy with JDK1.3
where we use enums
retrieve enumeration datatype into jsp
Thread Question from Examlab
How to define constants for several classes?