我添加了三个带参数的方法:
public static void doSomething(Object obj) {
System.out.println("Object called");
}
public static void doSomething(char[] obj) {
System.out.println("Array called");
}
public static void doSomething(Integer obj) {
System.out.println("Integer called");
}
Run Code Online (Sandbox Code Playgroud)
当我调用时doSomething(null),编译器会将错误视为模糊方法.所以是问题,因为Integer和char[]方法,或Integer和Object方法呢?
我有以下代码的问题:
public static <T> T firstNonNull(@Nullable T first, @Nullable T second) {
return first != null ? first : second;
}
public static Set<String> getStrings() {
return new HashSet<>();
}
public static Set<String> doesNotCompile = firstNonNull(getStrings(), new HashSet<>());
Run Code Online (Sandbox Code Playgroud)
使用JDK 8直到更新11,此代码编译.使用JDK 8 update 20,它不再编译.在最后一个语句中,我必须显式指定String最后一个HashSet实例化的类型参数.
我想知道这个代码是否错误,或者它是否是最后一次JDK更新中的回归.