Is there any way I can reference this::method using a more generic type like below?
Number method(Integer input){ return 1;}
void test(){
Function<Integer, Number> ref = this::method; //OK
Function<Number, Number> moreGenericRef = this::method // does not compile.
Function<? extends Number, Number> moreGenericRef2 = this::method // does not compile.
}
I want to be able to do the following.
Map<String, Function<Number,Number>> maps;
maps.add("method1", this::method)
maps.add("method2", this::method2)
maps.get("methods1").apply(1.2);
maps.get("methods2").apply(1);
The functions are adapters that will be called by the mapper of Stream< Number >