HI Folks ,

Sorry if it is the Repeated Question....

---> I want to Create An Object for a Class With user specified name.?


Example :
Class Name : Simple
User Specified Name for a Object : SunServer

i want like this

Simple "userSpecified Name" = new Simple();
how to replace the "userSpecified Name " variable in the above line with SunServer..

String UserSpecified = SunServer;
:'( Simple UserSpecified = new Simple();:'(

Above line is Wrong bcz we already defined UserSpecified Variable as a String Type and we cant create an Object for a class(Simple) with same variable.

i want to do create Objects with name as User specified "Something like at Runtime"
.

Recommended Answers

All 2 Replies

are you wanting dynamic variable names?

if so you can't do that in java
you can use an ArrayList or HashMap to store a name and a class

String userSpecifiedName = "SunServer";
HashMap<String, Simple> map = new HashMap<String, Simple>();

Simple simpleClass = new Simple();
map.put(userSpecifiedName, simpleClass);
commented: Yeah, he seems to be wanting a map. Not a very clear question though :) +15

thanks man i got it

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.