< prev index next > src/java.base/share/classes/java/lang/runtime/ObjectMethods.java
Print this page
private static final MethodType MT_OBJECT_BOOLEAN = MethodType.methodType(boolean.class, Object.class);
private static final MethodType MT_INT = MethodType.methodType(int.class);
private static final MethodTypeDesc MTD_OBJECT_BOOLEAN = MethodTypeDesc.of(CD_boolean, CD_Object);
private static final MethodTypeDesc MTD_INT = MethodTypeDesc.of(CD_int);
- private static final HashMap<Class<?>, MethodHandle> primitiveEquals = new HashMap<>();
+ /* package-private */
+ static final HashMap<Class<?>, MethodHandle> primitiveEquals = new HashMap<>();
+
private static final HashMap<Class<?>, MethodHandle> primitiveHashers = new HashMap<>();
static {
try {
Class<ObjectMethods> OBJECT_METHODS_CLASS = ObjectMethods.class;
requireNonNull(recordClass);
requireNonNull(names);
requireNonNull(getters);
Arrays.stream(getters).forEach(Objects::requireNonNull);
MethodType methodType;
- if (type instanceof MethodType mt)
+ if (type instanceof MethodType mt) {
methodType = mt;
- else {
+ if (mt.parameterType(0) != recordClass) {
+ throw new IllegalArgumentException("Bad method type: " + mt);
+ }
+ } else {
methodType = null;
if (!MethodHandle.class.equals(type))
throw new IllegalArgumentException(type.toString());
}
List<MethodHandle> getterList = List.of(getters);
+ for (MethodHandle getter : getterList) {
+ if (getter.type().parameterType(0) != recordClass) {
+ throw new IllegalArgumentException("Bad receiver type: " + getter);
+ }
+ }
MethodHandle handle = switch (methodName) {
case "equals" -> {
if (methodType != null && !methodType.equals(MethodType.methodType(boolean.class, recordClass, Object.class)))
throw new IllegalArgumentException("Bad method type: " + methodType);
yield makeEquals(lookup, recordClass, getterList);
< prev index next >