8268124: Update java.lang to use switch expressions

Reviewed-by: naoto, darcy, mchung, iris, lancea, dfuchs
This commit is contained in:
Patrick Concannon 2021-06-10 11:12:37 +00:00
parent a187fcc3ec
commit d43c8a74b3
22 changed files with 421 additions and 551 deletions

View file

@ -274,32 +274,26 @@ public class MethodHandleProxies {
}
private static boolean isObjectMethod(Method m) {
switch (m.getName()) {
case "toString":
return (m.getReturnType() == String.class
&& m.getParameterCount() == 0);
case "hashCode":
return (m.getReturnType() == int.class
&& m.getParameterCount() == 0);
case "equals":
return (m.getReturnType() == boolean.class
&& m.getParameterCount() == 1
&& m.getParameterTypes()[0] == Object.class);
}
return false;
return switch (m.getName()) {
case "toString" -> m.getReturnType() == String.class
&& m.getParameterCount() == 0;
case "hashCode" -> m.getReturnType() == int.class
&& m.getParameterCount() == 0;
case "equals" -> m.getReturnType() == boolean.class
&& m.getParameterCount() == 1
&& m.getParameterTypes()[0] == Object.class;
default -> false;
};
}
private static Object callObjectMethod(Object self, Method m, Object[] args) {
assert(isObjectMethod(m)) : m;
switch (m.getName()) {
case "toString":
return self.getClass().getName() + "@" + Integer.toHexString(self.hashCode());
case "hashCode":
return System.identityHashCode(self);
case "equals":
return (self == args[0]);
}
return null;
return switch (m.getName()) {
case "toString" -> self.getClass().getName() + "@" + Integer.toHexString(self.hashCode());
case "hashCode" -> System.identityHashCode(self);
case "equals" -> (self == args[0]);
default -> null;
};
}
private static Method[] getSingleNameMethods(Class<?> intfc) {