-1

Possible Duplicate:
How do I programmatically compile and instantiate a Java class?

How to create a new java class at runtime?

Community
  • 1
  • 1
dheeps
  • 163
  • 1
  • 4
  • 13
  • It is possible with BCEL but why would you want to do that? How would you use it? – biziclop Feb 23 '11 at 11:44
  • @Balus, are you sure it's a duplicate? This question is about dynamically defining a class. The question you've linked is about dynamically creating an instance of an existing class. – Grzegorz Oledzki Feb 23 '11 at 12:00
  • @Grze: don't read only titles. The question, at least the answer, in question also also covers dynamically creating a class :) Edit: I've improved the title of the other question a bit. – BalusC Feb 23 '11 at 12:01
  • What do you need it for? Perhaps what you really want to do can be done using anonymous inner classes. – Axel Feb 23 '11 at 12:57
  • @Balus: You're right. I read the title and the question, but didn't look at the answers. – Grzegorz Oledzki Feb 23 '11 at 14:01

1 Answers1

0

Use Class<?> ClassLoader.defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain)

The problem is that this method is protected. So, you should extend class loader with your own class and call this method from there.

AlexR
  • 114,158
  • 16
  • 130
  • 208