T is place holder that should be filled
that's OK :
public class Computator <N extends Number> {
public N sum (N n) {
return n;
}
that's is not :
public class Computator <N extends Number> {
public N sum () {
double n = 1.1;
return n;
}
Computator<Integer, List<Integer>> c = new Computator<>(); //line 6
N - generic class param type passed as Integer
public N sum (C collection) //line 2
so return type for sum(C collection) is Integer
double sum = 0.0; //line 3
...
retrun sum; //line 7
variable "sum" has a type as a primitive double.
it will be compile error.
answer: D
D is correct, only for safe type N extends of number but the return type is a double, even double extends from a double, Class N can be any class that extends, compilator does unknown the type so prevent this compilator error thworn.
return type must be double
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
3 months, 3 weeks agoASPushkin
2 weeks, 1 day agod7bb0b2
11 months agoStavok
1 year, 6 months agoRP384
1 year, 10 months ago