Generics return type not working
-
12-11-2019 - |
문제
I'm going through example.
public interface Visitor<T> {
public void visit(T e);
}
class Sum<T extends Integer> implements Visitor<T> {
private int sum = 0;
@Override
public void visit(T element) {
sum += element;
}
public T value() {
return sum;
}
}
The return statement T value() return sum is giving error stating that Type mismatch: cannot convert from int to T. Why it is so and how to fix the problem.
올바른 솔루션이 없습니다
제휴하지 않습니다 StackOverflow