Confused on this one (The error is on assigning f2 = func1).
- Why is creating func1 not an error as we are using Number.shortValue() but defined a lower bound as a Number?
- If
func1can be created this way then why cannot it be assigned tof2?
Thanks for your help.
Function<? super Number, ? extends String> func1 = obj -> String.valueOf(obj.shortValue());
Function<Integer, String> f2 = func1;
The error is:
Incompatible types. Found: 'java.util.function.Function<capture<? super java.lang.Number>,capture<? extends java.lang.String>>', required: 'java.util.function.Function<java.lang.Integer,java.lang.String>'