I'm trying to write a curious method:
Map<Class, AbstractTool> ToolMap = new HashMap<Class, AbstractTool>(); //init'd correctly @SuppressWarnings("unchecked") public <T extends AbstractTool> T getTool(Class cls){ if (ToolMap.containsKey(cls)) { return (T) ToolMap.get(cls); } else return null; } In a weird twist of events, this code actually does what I need it to do. My main issue is the fact that in order to call it, i have to make these big calls:
this.getTool<ToolType>(ToolType.class); Not Cool.
Is there a way to write this method so that it has the following signature?:
ToolType t = this.getTool<ToolType>(); or this one
ToolType t = this.getTool(ToolType); // This one seems impossible without casting.