Reputation: 147
I am in a situation where I cannot use reflection at all. Needless to say, I also need to dynamically create classes. As there something already created out there that allows you to create virtual java objects. Just off of the top of my head, a java virtual object would be ... say a map of Strings to objects, where the Strings are names, and the objects are the objects themselves. Of course you could add all kinds of meta-data in there, like another map that contains privacy, etc. Does something like this exist? Also, instead of doing the way I described above (using maps, etc) what about if I created a class in binary form?
Upvotes: 0
Views: 2945
Reputation: 64065
It's possible to compile a class on the fly from source using the compiler API, though I have never done it. See the javax.tools package.
It's also possible to load a class from a byte array of class data. See java.lang ClassLoader.
But why not just do as you suggest and have a Map<String,Object>
?
Upvotes: 1