DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Creating Objects With User specified Name (http://www.daniweb.com/forums/thread157847.html)

babusek Nov 17th, 2008 8:05 am
Creating Objects With User specified Name
 
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"
.

dickersonka Nov 17th, 2008 9:49 am
Re: Creating Objects With User specified Name
 
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);

babusek Nov 18th, 2008 7:00 am
Re: Creating Objects With User specified Name
 
thanks man i got it


All times are GMT -4. The time now is 2:47 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC