This content has been marked as final. Show 3 replies
Oh how very nice! Thank you. I, for some reason, cannot fully get my head around generics, though I do everything I can to utilize them to their fullest.
I didn't want to type the class because on each call of getMap, I might need a different type key, and didn't want to create singletons for my purpose.
ejp wrote:Or from the assignment context:
provided K is inferable from the arguments.
Set<String> empty = Collections.emptySet();
Otherwise you have to parameterise the class on <K, M>.You may also specifically provide K when you use the method if the context doesn't give the compiler enough information or if you want to override it.
Edited by: endasil on 14-May-2010 4:13 PM
Set<Object> singleton1 = Collections.singleton("Hello"); //error Set<Object> singleton2 = Collections.<Object>singleton("Hello"); //fine