I wondered if it was possible to create a “templatized” getter, such as :
class TestGet
{
private static Map<String,Object> theMap.....
public static getObject<T>(String key).....
And somewhere in the code, something like :
JButton myButton = TestGet.getObject<JButton>("theButton");
Beware : this is just an “idle” question, I’m trying to avoid “dirty” casts in my code since they make my eyes bleed each time I look at them.
I know there are more elegant ways to do that, but I really would do it with a map of to avoid linking with other classes.
I tried out some configurations, but nothing seems to fit what I want to do… Is a templating like that just possible ?
You can write
and
or just
For a more complicated example 😉