开发者

how to create a dynamic class at runtime in Java

Is it possible to create a new Java file from an existing Java file aft开发者_StackOverflow社区er changing some of its attributes at runtime?

Suppose I have a java file

public class Student {
    private int rollNo;
    private String name;
    // getters and setters
    // constructor
}

Is it possible to create something like this, provided that rollNo is a key element for the table?

public class Student {
    private StudentKey key;
    private String name;
    //getters and setters
    //constructor
}

public class StudentKey {
    private int rollNo;
    // getters and setters
    // construcotors
}

Please help. Thanks.


Take a look at javassist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜