[jboss-dev-forums] [Design of JBossCache] - Re: JBCACHE-1004 and JBCACHE-1005

jason.greene@jboss.com do-not-reply at jboss.com
Thu Mar 15 15:42:22 EDT 2007


"manik.surtani at jboss.com" wrote : Well, one workaround is to use a return type rather than a cast, which is valid:
  | .

You don't need to do this. Since a DI framework does this at runtime the generics info is irrelevant. So you can declare the injected type to be whatever you want. To demonstrate:


  | public class GenericsFun
  | {
  |    private Map<String, Integer> foo = new HashMap<String, Integer>();
  | 
  |    public static void main(String[] args) throws Exception
  |    {
  |       HashMap<Long, Long> map = new HashMap<Long, Long>(); 
  |       map.put(5L, 6L);
  |       GenericsFun fun = new GenericsFun();
  |       Field field = GenericsFun.class.getDeclaredField("foo");
  |       field.setAccessible(true);
  |       field.set(fun, map);
  |       fun.throwCCE();
  |    }
  |    
  |    public void throwCCE()
  |    {
  |       Integer boom = foo.get(5L);
  |    }
  | }
  | 

-Jason

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4028513#4028513

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4028513



More information about the jboss-dev-forums mailing list