Hi all,
first of all I apologize for submitting a problem that is not directly related to Spring but to Java. My only excuse is that there are a lot of highly experienced Java gurus in the forum, and I have not been able to google up for a solution for days now.
I have a method that will return a Map<K,V>. The actual Map class shall be passed as parameter to the method, such as here:
This looks fine, and even compiles without problems. However I have not found a way to call that method without either receiving an unchecked conversion warning, or I need to add the @SuppressWarnings("unchecked") annotation (which I do not want).Code:public <K,V,T extends Map<K, V>> T loadMap(Class<T> clazz);
I tried
Has anyone got a picture on how to correctly spell a class parameter using generics?Code:// works but gives a warning Map<String, Long> myMap = loadMap(HashMap.class); // obviously gives a compiler error Map<String, Long> myMap = loadMap(HashMap<String, Long>.class); // doesn't work either Map<String, Long> myMap = loadMap(Class<HahMap<String.Long>>);
Thanks for any pointer, and even for a "no way" if you're quite sure about that ;-)
And sorry again for the OT question.
Regards,
Ernest


Reply With Quote
