hey guys , i had a problem with classes and objects , i need to get the class name form a text file for example and open an object from that class , is that possible if so how can i do it . the object parameters i can send it according the user inputs.

for example can i say :

String ClassName = "class_name";
then ClassName cn = new ClassName;

i know that the piece of code above sounds insane but i need a way to do it urgently
thanks in advance =)

Recommended Answers

All 5 Replies

It's called reflection. Google that and find a tutorial.

i searched for a tutorials but i didn't find how to open an instance of a class
for example

<code>
String input = "Class";
Class c = input.getClass();
</code>

also i can know every thing about the class's methods and constructor thanks to your hint but i still don't know how to open an instance or an object of that class

Using the class Class you can
1. Get an instance of Class from a String containing the name of the desired class and
2. Create an instance of the class defined by that instance of Class.
Details of these 2 methods are in the API doc for Class.

ok can you send me a link to that please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.