• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics Enum type values?

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to run a static method on a parameterized type. Specifically, I have a class that is parameterized with an Enum. From within the class, I'd like to get to the Enum's values. Here's an example of what I'm trying to do.

The "public T[] values()" method won't compile.
[ December 02, 2008: Message edited by: Max Rahder ]
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i think that you cannot do that not in that way. Because you are trying to return the values of an erased type. When you are gonna execute the method values from the Test.class you're actually returning Object[] and the compiler insert a cast to Marx but inside the method you cannot know that type because of how erasure works.

This it's my approach to what you posted


You could substitute the Parameter T in a Child class of Test and that's the only way that i know, that the ParameterizedType can be inferred, like the example below:


[ December 02, 2008: Message edited by: Nitesh Kant ]
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Angel, I think you're right. I'll do as you suggest and pass the enumeration class reference into the constructor, and save it for use in returning its values, as shown below. Thanks again!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic