• Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamically calling class that takes param in constructor  RSS feed

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've searched and read posts in this forum about Class.forName, but I'm still confused. Say I have the following code:

What I really want is to be able to construct blueDog with the String "blue" so that when I call getColor() on it it says "blue"! Is there a simple way to do this?
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got some help from http://java.sun.com/docs/books/tutorial/reflect/object/arg.html and imported java.lang.reflect.* and changed my main method to this and it worked:

Seems I wasn't using quite the right search terms on Google to find that helpful page the first time around!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!