943,865 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 663
  • Java RSS
Nov 17th, 2008
0

Creating Objects With User specified Name

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
babusek is offline Offline
28 posts
since Oct 2008
Nov 17th, 2008
1

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

Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

Re: Creating Objects With User specified Name

thanks man i got it
Reputation Points: 10
Solved Threads: 1
Light Poster
babusek is offline Offline
28 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: I need some advice
Next Thread in Java Forum Timeline: Menu App





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC