blob: c126461a9929c563fceedeee33fef09302747965 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import java.util.*;
public aspect GenericMethods {
declare warning : execution(Object whoAmI(Object))
: "static generic method match";
declare warning : withincode(Number myFavourite(List))
: "instance generic method match";
// should we have an XLint to explain why the pointcut below does not match?
declare warning : execution(* myFavourite(List<Number>))
: "no match because erasure is List";
}
class PlainClassWithGenericMethods {
public static <T> T whoAmI(T t) {
return t;
}
public <S extends Number> S myFavourite(List<S> ls) {
return ls.get(0);
}
}
class GenericClassWithGenericMethods<N> {
N n;
public static <T> T whoAmI(T t) {
return t;
}
public <S extends Number> S myFavourite(List<S> ls) {
return ls.get(0);
}
}
|