I have a parametrized value, that is resolved at runtime:
public class GenericsMain {
    public static void main(String... args) {
        final String tag = "INT";
        Field field = resolve(tag);
        if (tag.equals("INT")) {
            /*
                In here I am using the "secret knowledge" that if tag equals INT, then
                field could be casted to Field<Integer>. But at the same time I see an unchecked cast
                warning at here.
                Is there a way to refactor the code to be warning-free?
             */
            Field<Integer> integerField = (Field<Integer>) field;
            foo(integerField);
        }
    }
    public static Field resolve(String tag) {
        switch (tag) {
            case "INT":
                return new Field<>(1);
            case "DOUBLE":
                return new Field<>(1.0d);
            default:
                return null;
        }
    }
    public static <T> void foo(Field<T> param) {
        System.out.println(param.value);
    }
    static class Field<T> {
        public final T value;
        public Field(T value) {
            this.value = value;
        }
    }
}
Is there a way to avoid unchecked cast in the code above (marked with a long comment)?
 
     
     
     
    