I have a common code that I cannot figure out how to legally prevent the receipt of warnings; I am using @SuppressWarnings ("unchecked") at the moment, as it seems that generic type casting cannot be performed without warnings.
How can I get rid of the annotation?
I have:
public MyObject(SharedContext<Object> ctx) { super(ctx); // set protected field 'context' ... context.set("Input Fields" ,Collections.synchronizedMap(new TreeMap<String,Pair<String,Boolean>>(String.CASE_INSENSITIVE_ORDER))); context.set("Output Fields" ,Collections.synchronizedMap(new TreeMap<String,String> (String.CASE_INSENSITIVE_ORDER))); context.set("Event Registry",new EventRegistry(log) ); } @SuppressWarnings("unchecked") protected void startup() { inputFields =(Map<String,Pair<String,Boolean>>)context.get("Input Fields" ,null); outputFields =(Map<String,String> )context.get("Output Fields" ,null); eventRegistry =(EventRegistry )context.get("Event Registry",null); ... }
The context of the protected variable is the type SharedContext<Object> .
Without annotation, the compiler generates warnings:
...\MyClass.java:94: warning: [unchecked] unchecked cast found : java.lang.Object required: java.util.Map<java.lang.String,com.mycompany.Pair<java.lang.String,java.lang.Boolean>> inputFields =(Map<String,Pair<String,Boolean>>)context.get("Input Fields" ,null); ^ ...\MyClass.java:95: warning: [unchecked] unchecked cast found : java.lang.Object required: java.util.Map<java.lang.String,java.lang.String> outputFields =(Map<String,String> )context.get("Output Fields" ,null);
java generics warnings
Lawrence dol
source share