Creating Objects With User specified Name

Reply

Join Date: Oct 2008
Posts: 26
Reputation: babusek is an unknown quantity at this point 
Solved Threads: 1
babusek babusek is offline Offline
Light Poster

Creating Objects With User specified Name

 
0
  #1
Nov 17th, 2008
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"
.
Last edited by babusek; Nov 17th, 2008 at 8:05 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,158
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 136
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Creating Objects With User specified Name

 
1
  #2
Nov 17th, 2008
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

  1. String userSpecifiedName = "SunServer";
  2. HashMap<String, Simple> map = new HashMap<String, Simple>();
  3.  
  4. Simple simpleClass = new Simple();
  5. map.put(userSpecifiedName, simpleClass);
Last edited by dickersonka; Nov 17th, 2008 at 9:49 am.
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 26
Reputation: babusek is an unknown quantity at this point 
Solved Threads: 1
babusek babusek is offline Offline
Light Poster

Re: Creating Objects With User specified Name

 
0
  #3
Nov 18th, 2008
thanks man i got it
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC