简体   繁体   English

我如何使用bytebuddy生成pojo代码

[英]How can I use bytebuddy to generate pojo code

I'm new to bytebuddy, and I've written a junit test to generate a class file. 我是bytebuddy的新手,并且编写了一个junit测试来生成类文件。 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. 只是Java代码,而不是类文件。 So, does byte buddy can do This? 那么,字节伙伴可以做到这一点吗? Or, I will only to use code model lib. 或者,我只会使用代码模型库。

Byte Buddy is a class for generating byte code, not Java source code. 字节伙伴是用于生成字节代码而不是Java源代码的类。 For generating source code, have a look at Java poet: https://github.com/square/javapoet 要生成源代码,请看一下Java诗人: https : //github.com/square/javapoet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM