I'm trying to migrate Java 7 code to Java 8, so I've code similar to:
package tests;
import java.util.Arrays;
import java.util.Map;
public class Tests {
private static interface ComparableMap<K,V> extends Map<K,V>, Comparable {}
public static void main(String[] args) {
func(getString());
}
private static void func(Comparable...input){
System.out.println(Arrays.toString(input));
}
private static void func(ComparableMap <?,?> m){
System.out.println(m);
}
private static <T extends Comparable> T getString(){
return (T) "aaa";
}
}
In java 7 it working properly, in java 8 I'm getting:
java.lang.ClassCastException: java.lang.String cannot be cast to tests.Tests$ComparableMap
And in case I'm changing one function definition to:
private static <T> T getString(){
return (T) "aaa";
}
compilation will fail with: error:
reference to func is ambiguous
Why Java 8 compiler not failing in first case? (Looks bug to me) Is it possible to change 2nd overloaded function, in order to get called first function with varargs argument without changing call itself?