Java: getClass() of bounded type

If getClass() returns Class<? extends X>, nothing really bad can happen; actually it’ll help a lot of use cases. The only problem is, it is not theoretically correct. if an object is an ArrayList<String>, its class cannot be Class<ArrayList<String>> – there is no such class, there is only a Class<ArrayList>. This is actually not related … Read more

What is the difference between bounded wildcard and type parameters?

They expose different interfaces and contract for the method. The first declaration should return a collection whose elements type is the same of the argument class. The compiler infers the type of N (if not specified). So the following two statements are valid when using the first declaration: Collection<Integer> c1 = getThatCollection(Integer.class); Collection<Double> c2 = … Read more