How to create a dynamic class at run time 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

pubic class Student{

    private int rollNo;
    private String name;
    // getters and setters
    // constructor
}

you can 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..

+5
source share
1 answer

Take a look at the javassist .

+4
source

All Articles