Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created October 5, 2019 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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