This code doesn't compiled
"T is not found"
it will compile if written something like this
public static <T extends Integer> void printValue(Function f, T num) {
There is no correct answer
This code, for example, remove the compile warning :
public static void main(String[] args) {
Function <Integer, Integer> triple = x -> {
return x*3;
};
MyClass.printValue(triple, 4);
}
public static void printValue(Function<Integer, Integer> f, int num) {
System.out.println(f.apply(num));
}
"T is not found"
use bounded type parameters like <T extends Integer>
or change T to Integer or int (A,D)
"...uses unchecked or unsafe operations."
the reason is using raw code
use generics
Function<Integer, Integer>
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
6 months, 3 weeks agoASPushkin
2 months, 1 week agodilleman
1 year, 3 months agoStavok
1 year, 5 months ago