• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Creating a Class on-the-fly  RSS feed

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection works on existing classes, but a library like Javassist can easily create classes on the fly.
 
Sheriff
Posts: 23866
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However you would certainly need to use reflection to create and access instances of that class after you had created it.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless it implements an interface.
 
Sheriff
Posts: 21463
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple Map<String,String> looks easier to accomplish.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!