1 Reply Latest reply: Jan 13, 2009 4:14 PM by 807589 RSS

    Class<?>.cast for generics

    807589
      class Goo<T extends Hoo> {
      }
      
      Class Foo {
           private Map<Class<?>, Goo<?>> m_GooByType;
           
           public Goo<?> getGoo(Class<? extends Hoo> type) {
                return m_GooByType.get(type);
           }
      }
      Works, but would rather do the the following:
      Class Foo {
           private Map<Class<?>, Goo<?>> m_GooByType;
           
           public <T extends Hoo> Goo<T> getGoo(Class<T> type) {
                return Goo<T>.class.cast(m_GooByType.get(type));
           }
      }
      It seems the language does support .class operation for a generic type.

      Really, a language feature to complete the use of generics.