Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a dynamic class at runtime in Java

Is it possible to create a new Java file from an existing Java file after 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.

like image 415
M.J. Avatar asked Oct 15 '22 04:10

M.J.


1 Answers

Take a look at javassist.

like image 98
Rhangaun Avatar answered Oct 18 '22 11:10

Rhangaun