0

I'm new to bytebuddy, and I've written a junit test to generate a class file. Blow is my code:

@Test
public void testGener() throws IOException {
    DynamicType type = new ByteBuddy().subclass(Object.class).name("TestInterFace").defineField("test", String.class, Visibility.PUBLIC).make();
    type.saveIn(new File("C:/Users/zhouxiang/Desktop/develop"));
}

But, what I really need is to print a string like this:

public class TestInterFace
{
  public String test;
}

yes. Just the Java code, not the class file. So, does byte buddy can do This? Or, I will only to use code model lib.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
zhouxiang
  • 153
  • 3
  • 12

1 Answers1

4

Byte Buddy is a class for generating byte code, not Java source code. For generating source code, have a look at Java poet: https://github.com/square/javapoet

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192