I have an issue about how to create class(not instance) dynamically. In my project, I need to write several similar class according to the configuration file. For exmaple, there is a JSON like this:
{
{
"lang": "python",
"file": "class1.py",
"args": ["arg1"]
},
{
"lang": "python",
"file": "class2.py"
"args": ["arg2"]
}
}
Subsequently, I need to write two java class below:
class1:
public class Class1 extends ShellBolt implements IRichBolt {
public Class1() {
super("python", "class1.py");
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields(arg1));
}
@Override
public Map<String, Object> getComponentConfiguration() {
return null;
}
}
class2:
public class Class2 extends ShellBolt implements IRichBolt {
public Class2() {
super("python", "class2.py");
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields(arg2));
}
@Override
public Map<String, Object> getComponentConfiguration() {
return null;
}
}
But if the JSON file is added a new object:
{
"lang": "python",
"file": "class3.py"
"args": ["arg3"]
}
I need to write a new Class with the similar structure. So, is there a way to create class dynamically? I know maybe cglib might works, but I hava no idea how to use it in my case. Thanks.