--- a/jdk/test/java/lang/invoke/InvokeGenericTest.java Thu Jan 05 08:42:40 2012 -0800
+++ b/jdk/test/java/lang/invoke/InvokeGenericTest.java Wed Jan 18 17:34:29 2012 -0800
@@ -45,6 +45,7 @@
*
* @author jrose
*/
+@SuppressWarnings("cast") // various casts help emphasize arguments to invokeExact
public class InvokeGenericTest {
// How much output?
static int verbosity = 0;
@@ -129,7 +130,7 @@
}
}
- static List<Object> calledLog = new ArrayList<Object>();
+ static List<Object> calledLog = new ArrayList<>();
static Object logEntry(String name, Object... args) {
return Arrays.asList(name, Arrays.asList(args));
}
@@ -237,8 +238,7 @@
else
try {
return param.newInstance();
- } catch (InstantiationException ex) {
- } catch (IllegalAccessException ex) {
+ } catch (InstantiationException | IllegalAccessException ex) {
}
return null; // random class not Object, String, Integer, etc.
}
@@ -274,9 +274,11 @@
return zeroArgs(params.toArray(new Class<?>[0]));
}
+ @SafeVarargs @SuppressWarnings("varargs")
static <T, E extends T> T[] array(Class<T[]> atype, E... a) {
return Arrays.copyOf(a, a.length, atype);
}
+ @SafeVarargs @SuppressWarnings("varargs")
static <T> T[] cat(T[] a, T... b) {
int alen = a.length, blen = b.length;
if (blen == 0) return a;
@@ -311,7 +313,7 @@
int beg, int end, Class<?> argType) {
MethodType targetType = target.type();
end = Math.min(end, targetType.parameterCount());
- ArrayList<Class<?>> argTypes = new ArrayList<Class<?>>(targetType.parameterList());
+ ArrayList<Class<?>> argTypes = new ArrayList<>(targetType.parameterList());
Collections.fill(argTypes.subList(beg, end), argType);
MethodType ttype2 = MethodType.methodType(targetType.returnType(), argTypes);
return target.asType(ttype2);
@@ -320,7 +322,7 @@
// This lookup is good for all members in and under InvokeGenericTest.
static final Lookup LOOKUP = MethodHandles.lookup();
- Map<List<Class<?>>, MethodHandle> CALLABLES = new HashMap<List<Class<?>>, MethodHandle>();
+ Map<List<Class<?>>, MethodHandle> CALLABLES = new HashMap<>();
MethodHandle callable(List<Class<?>> params) {
MethodHandle mh = CALLABLES.get(params);
if (mh == null) {
@@ -353,8 +355,8 @@
countTest();
String[] args = { "one", "two" };
MethodHandle mh = callable(Object.class, String.class);
- Object res; List resl;
- res = resl = (List) mh.invoke((String)args[0], (Object)args[1]);
+ Object res; List<?> resl;
+ res = resl = (List<?>) mh.invoke((String)args[0], (Object)args[1]);
//System.out.println(res);
assertEquals(Arrays.asList(args), res);
}
@@ -365,8 +367,8 @@
countTest();
int[] args = { 1, 2 };
MethodHandle mh = callable(Object.class, Object.class);
- Object res; List resl;
- res = resl = (List) mh.invoke(args[0], args[1]);
+ Object res; List<?> resl;
+ res = resl = (List<?>) mh.invoke(args[0], args[1]);
//System.out.println(res);
assertEquals(Arrays.toString(args), res.toString());
}
@@ -377,8 +379,8 @@
countTest();
String[] args = { "one", "two" };
MethodHandle mh = callable(Object.class, String.class);
- Object res; List resl;
- res = resl = (List) mh.invoke((String)args[0], (Object)args[1]);
+ Object res; List<?> resl;
+ res = resl = (List<?>) mh.invoke((String)args[0], (Object)args[1]);
//System.out.println(res);
assertEquals(Arrays.asList(args), res);
}
@@ -440,9 +442,9 @@
* A void return type is possible iff the first type is void.class.
*/
static List<MethodType> allMethodTypes(int minargc, int maxargc, Class<?>... types) {
- ArrayList<MethodType> result = new ArrayList<MethodType>();
+ ArrayList<MethodType> result = new ArrayList<>();
if (types.length > 0) {
- ArrayList<MethodType> argcTypes = new ArrayList<MethodType>();
+ ArrayList<MethodType> argcTypes = new ArrayList<>();
// build arity-zero types first
for (Class<?> rtype : types) {
argcTypes.add(MethodType.methodType(rtype));
@@ -456,7 +458,7 @@
if (argc >= maxargc)
break;
ArrayList<MethodType> prevTypes = argcTypes;
- argcTypes = new ArrayList<MethodType>();
+ argcTypes = new ArrayList<>();
for (MethodType prevType : prevTypes) {
for (Class<?> ptype : types) {
argcTypes.add(prevType.insertParameterTypes(argc, ptype));
@@ -524,8 +526,8 @@
countTest();
Object[] args = { 1, 2 };
MethodHandle mh = callable(Object.class, int.class);
- Object res; List resl; int resi;
- res = resl = (List) mh.invoke((int)args[0], (Object)args[1]);
+ Object res; List<?> resl; int resi;
+ res = resl = (List<?>) mh.invoke((int)args[0], (Object)args[1]);
//System.out.println(res);
assertEquals(Arrays.asList(args), res);
mh = MethodHandles.identity(int.class);