class Foo { public static void main(String[] args) { final boolean b = false; final Integer i = (Integer)3; final short s = (short)(b ? i : (int)Integer.valueOf(3)); System.out.println(s); } } class NonPrimitiveType { @SuppressWarnings("unchecked") public void apply(Fun, ?> defaultGetter, Class configType, Fun, T> getter) { (getter == null ? (Fun)defaultGetter : getter).apply(configType); } interface Fun { R apply(T t); } }