The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

I agree with you...

Posted by Kishori Sharan on September 18, 2000 at 1:31 PM

Hi
You cannot cast an object just by having a class name in a string. So you have to use the class as
B bb = ( B ) Factory.create ( "B" ) ;
Just to simplify coding you can create static methods like createB ( ), createC ( ) which will return a reference of object of class B and C respectively and from within those methods call your original create ( "Classname" ) method , typecast the returned object to appropriate type and return it. This way you don't have to type cast the objects everytime you call create() and you can use

B bb = Factory.createB ( ) ;

I agree with you that Reflection is missing the functionality you have mentioned in your query.

Thanx
Kishori



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us