Boltimuss
Boltimuss

Reputation: 147

Java Virtual Objects

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

Answers (2)

L. Cornelius Dol
L. Cornelius Dol

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

jmo
jmo

Reputation: 452

You could look at using a Dynabean from apache commons beanutils.

Not sure how much value it would provide over just a normal map.

Upvotes: 0

Related Questions