@Override boolean adapt(int opcode, String owner, String name, String desc, MethodVisitor delegate) { if (opcode == fieldOpcode) { Type t = Type.getType(desc); boolean expectedReference = isReferenceType(t); if (actuallyPrimitive ^ expectedReference) { // rewrite "x.y" to "(T)x.z()". // we'll leave it up to HotSpot to optimize away casts delegate.visitMethodInsn(invokeOpcode, owner, methodName, methodDescriptor); if (expectedReference) delegate.visitTypeInsn(CHECKCAST, t.getInternalName()); return true; } } return false; }
@Override boolean adapt(int opcode, String owner, String name, String desc, MethodVisitor delegate) { if (opcode == fieldOpcode) { Type t = Type.getType(desc); boolean expectedReference = isReferenceType(t); if (actuallyPrimitive ^ expectedReference) { // rewrite "x.y=v" to "x.z(v)" // we expect the argument type to match delegate.visitMethodInsn(invokeOpcode, owner, methodName, methodDescriptor); return true; } } return false; }