File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Creating a Class on-the-fly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Creating a Class on-the-fly" Watch "Creating a Class on-the-fly" New topic
Author

Creating a Class on-the-fly

Dinesh Sundrani
Ranch Hand

Joined: Mar 21, 2006
Posts: 78
Hello,

I have a text file called class_content_decider.config and I would like to develop a simple Java Application (TestDynamicClass.java) that would read this 1-liner config file and create a DYNAMIC class (object on the fly).

Say for example - class_content_decider.config
firstanme, lastname, age, dob, company, salary

And the dynamic Class/Object should look like

Class temp1_21
{
String firstanme;
String lastname;
String age;
String dob;
String company;
String salary;
}

Would Reflection help in such a (specific) case?

Please suggest!

Regards,
DS - [SCJP, SCWCD, SCDJWS]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Reflection works on existing classes, but a library like Javassist can easily create classes on the fly.


Ping & DNS - updated with new look and Ping home screen widget
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

However you would certainly need to use reflection to create and access instances of that class after you had created it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Unless it implements an interface.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

A simple Map<String,String> looks easier to accomplish.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a Class on-the-fly
 
Similar Threads
Does this code will be valid for Composition?
Reading from a file
Using Named Queries
setter/getter in bean - overengineering?
code to read the xml and also overide the value of certain attributes in xml at runtime itself