@Test public void testHashCode() throws Exception { DynamicType.Loaded<?> loaded = new ByteBuddy() .subclass(Object.class) .defineField(FOO, type, Visibility.PUBLIC) .method(isHashCode()) .intercept(HashCodeMethod.usingOffset(0)) .make() .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER); assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0)); assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1)); assertThat(loaded.getLoaded().getDeclaredFields().length, is(1)); Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance(); instance.getClass().getDeclaredField(FOO).set(instance, value); assertThat(instance.hashCode(), is(hashOffset)); }
public static HashCodeMethod usingOffset(int value) { return new HashCodeMethod(new OffsetProvider.ForFixedValue(value)); }
HashCodeMethod implements Implementation { public static HashCodeMethod usingOffset(int value) { return new HashCodeMethod(new OffsetProvider.ForFixedValue(value)); } }
HashCodeMethod implements Implementation { public static HashCodeMethod usingOffset(int value) { return new HashCodeMethod(new OffsetProvider.ForFixedValue(value)); } protected  HashCodeMethod(OffsetProvider offsetProvider); private  HashCodeMethod(OffsetProvider offsetProvider,
                           int multiplier,
                           ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored,
                           ElementMatcher.Junction<? super FieldDescription.InDefinedShape> nonNullable); }
HashCodeMethod implements Implementation { public static HashCodeMethod usingOffset(int value) { return new HashCodeMethod(new OffsetProvider.ForFixedValue(value)); } protected  HashCodeMethod(OffsetProvider offsetProvider); private  HashCodeMethod(OffsetProvider offsetProvider,
                           int multiplier,
                           ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored,
                           ElementMatcher.Junction<? super FieldDescription.InDefinedShape> nonNullable); static HashCodeMethod usingSuperClassOffset(); static HashCodeMethod usingDefaultOffset(); static HashCodeMethod usingOffset(int value); HashCodeMethod withIgnoredFields(ElementMatcher<? super FieldDescription.InDefinedShape> ignored); HashCodeMethod withNonNullableFields(ElementMatcher<? super FieldDescription.InDefinedShape> nonNullable); Implementation withMultiplier(int multiplier); InstrumentedType prepare(InstrumentedType instrumentedType); ByteCodeAppender appender(Target implementationTarget); }
HashCodeMethod implements Implementation { public static HashCodeMethod usingOffset(int value) { return new HashCodeMethod(new OffsetProvider.ForFixedValue(value)); } protected  HashCodeMethod(OffsetProvider offsetProvider); private  HashCodeMethod(OffsetProvider offsetProvider,
                           int multiplier,
                           ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored,
                           ElementMatcher.Junction<? super FieldDescription.InDefinedShape> nonNullable); static HashCodeMethod usingSuperClassOffset(); static HashCodeMethod usingDefaultOffset(); static HashCodeMethod usingOffset(int value); HashCodeMethod withIgnoredFields(ElementMatcher<? super FieldDescription.InDefinedShape> ignored); HashCodeMethod withNonNullableFields(ElementMatcher<? super FieldDescription.InDefinedShape> nonNullable); Implementation withMultiplier(int multiplier); InstrumentedType prepare(InstrumentedType instrumentedType); ByteCodeAppender appender(Target implementationTarget);  }