/** Declare an identity method, a static generic method, and a nonstatic generic method */
declaration {
class Methods {
public static <T> T identity(T arg) { return arg; }
}
}
/** Invoke a simple identity method */
test {
String s = Methods.<String>identity("foo");
assert (s.equals("foo"));
Integer i = Methods.<Integer>identity(new Integer(23));
assert (i.equals(new Integer(23)));
}
/** Invoke a simple identity method with an argument subtype of T */
test {
Number n = Methods.<Number>identity(new Integer(23));
}
/** Assign the result to a correct inferred result type but an incorrect explicit result type */
static error {
<T> T identity(T arg) { return arg; }
Integer i = Methods.<Number>identity(new Integer(23));
}