Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Instantiate a class with a variable as its name
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="BogusException, post: 1605340"] The subject line says it all! This is an extension of a previous topic. I want to create an instance of a class, but want to refer to the name of the instance, at creation time, via a variable. So, if I were to make 3 classes in an iterative loop, I would be able to call the instances c1, c2, c3 programmatically. The equivelent is close to anonymous hashes and arrays in Perl, like $$someArrayName[0]; .. OK, so its not that close! The result is that each of the instantiated classes can then also be addressed programmatically-without knowing their exact instance name. So if I knew that I created 3 classes (which I would, as they were created iteratively), I could call a method common to all 3 one at a time. All of the Java documentation regarding anonymity refers to inner classes, which although powerful are not the same thing as an anonymous name for a class instance. Is this possible in Java? TIA! BogusException [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Instantiate a class with a variable as its name
Top