Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created October 5, 2019 19:46
Show Gist options
  • Save olegchir/7dcd7c079e610d2e0d06e3b4a273a743 to your computer and use it in GitHub Desktop.
Save olegchir/7dcd7c079e610d2e0d06e3b4a273a743 to your computer and use it in GitHub Desktop.
Class<?> dynamicType = new ByteBuddy()
.subclass(Object.class)
.method(ElementMatchers.named("toString"))
.intercept(FixedValue.value("Hello World!"))
.make()
.load(getClass().getClassLoader())
.getLoaded();
assertThat(dynamicType.newInstance().toString(), is("Hello World!"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment