Menu

[r4276]: / trunk / dynamicjava / testFiles / jlbench / ExplicitGenericMethods.jlbench  Maximize  Restore  History

Download this file

26 lines (22 with data), 751 Bytes

/** 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));
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.