-1

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

How to create a new java class at runtime?

5
  • It is possible with BCEL but why would you want to do that? How would you use it? Commented Feb 23, 2011 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. Commented Feb 23, 2011 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. Commented Feb 23, 2011 at 12:01
  • What do you need it for? Perhaps what you really want to do can be done using anonymous inner classes. Commented Feb 23, 2011 at 12:57
  • @Balus: You're right. I read the title and the question, but didn't look at the answers. Commented Feb 23, 2011 at 14:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.