I don't know if the title is understandable but I have this:
public class Product { public Integer getId() {...} public String getName() {...} } public <T,V> static void method(Function<T, V> f, V value) {...} and I want to become a compile error when:
method(Product::getId, "some String"); // id is not String method(Product::getName, 123); // name is not Integer But the compiler interpret V as:
java Serializable & Comparable<? extends Serializable & Comparable<?>> It compiles but depending on how "method" is implemented, you get an Exception at runtime or it just works wrongly.
How can I instruct the compiler to match the wanted data type? and I don't want to write a "method" for every possible V type.
Thanks!