• Post Reply Bookmark Topic Watch Topic
  • New Topic

Making an instance of a class from a String?

 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I posted a similar question today. I got some replies..thanks !
However I came across a similar problem.
The code below tries to create an instance of a class from a string. That is .. whatever the name of the String is that is what the name of the instancve of the class will be. The code is obviouly not compling.. can anyone take a look at it and make it work. Thanks a million!
here it is -->
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked this before and it would really be helpful to me if you could just tell me what you are trying to accomplish? That way I could give you a better answer that will help you accomplish that.
This code:
String link1 = Integer.toString(count);Link link1 = new Link();
won't work, because you can't declare the same variable to be two different types. Is link1 a String, or is it a Link? You only get to pick one!!
What are you trying to do here?
 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey rob ,
Ok lets see how best I can explain what am trying to do.
Ok lets put it this way.. I have 5 classes.
3 of the five classes generate a set of X and Y values that each can be used to plot a graph.
These 3 classes run in Parallel using a discrete
event simulation technique.
The 4th class is a dynamic array class.
Now this 4th class stores the values generated by each of the 3 classes. Of course each of the 3 classes makes an individual instance of the 4th class. This in not a problem. Everything is cool up to there.
The problem is the 5th class actually draws the graph. You see I can program each of the first 3 classes to make an instance of the 4th class. But how does the 4th class make an instance of the 5th class. Each instance of the 4th class must make a difereent instance of the 5th class.
So what I proposed to do was implnemnt a counter. Each time an instance of the 4th class was made it made an instance of the 5th class with the name 1 will be made. The counter was then incremented. SO if another instance of the 4th class was made then an instance of the 5th class named 2 would be made.
That is that I was trying to do with the code I printed before.
Am I making any sense? If am not please let me know and I'll see if i can explain it better.
Hey thanks for all the help so far ...
yours respectfully Avin Sinanan
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avin,
From your explanation it seems that you are going way to far. If we assume that the 4th class looks like the following:

Then every instance of Fourth will have a new instance of Fifth. What do we need to mess around with naming and integers for? If class Fourth wants to use its own instance of Fifth it just does. Let the compiler worry about names ...
Regards,
Manfred.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!