aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/generics/itds/StaticMethodITDOnGenericType.aj
blob: 91b51a61d21c03211ec2ed2c16b80fb25fbb4662 (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
/*
 * Static ITD of a method onto a generic type that utilises
 * a type variable from the target generic
 */
import java.util.*;

class MathUtils<N> { 

  public N doubleIt(N n) {
    int i = Integer.parseInt(n);
    return i*2;
  }

}

public class StaticMethodITDOnGenericType {
  public static void main(String[] argv) {
    List<Integer> ints = new ArrayList<Integer>();
    ints.add(10); 
    System.err.println("Double(10)=" + MathUtils<Integer>.doubleIt(5));
    System.err.println("First="      + MathUtils.first(ints));
  }
}


aspect X {
  // Using the type variable from the type. this is not a generic method.
  static E MathUtils<E>.first(List<E> elements) { return elements.get(0); }
}