Article View: borland.public.jbuilder.java.language
Article #17435Instantiate from name?
From: Doug Chamberlin
Date: Sat, 07 Nov 1998 00:00
Date: Sat, 07 Nov 1998 00:00
18 lines
1402 bytes
1402 bytes
I need to instantiate an object and all I have is the class name. I then want to invoke a method on the instantiated class. here are the details: All the classes I want to instantiate are descended from one of my classes. That ancestor class has a process() method which is abstract. Each of the descendent classes implements this process() method. Given the name of one of the descendent classes in a string parameter I want to instantiate that class and call its Process() method. I know if I use the newInstance() method to instantiate the class I will get the object I want. However, if I typecast it to the ancestor class and then call Process() the resulting method that is called is the ancestor's Process() method, right? How can I call the descendent's Process() method without typecasting to the descendent class (which I don't know until runtime)?
Technical Details
Message-ID:
<3644cdb7.167040536@wingate>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,4e9770e191c7aab0,start X-Google-Attributes: gidf74b3,public From: dchamberlinNOSPAM@dlawton.com (Doug Chamberlin) Subject: Instantiate from name? Date: 1998/11/07 Message-ID: <3644cdb7.167040536@wingate> X-Deja-AN: 409474795 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Organization: D. Lawton Associates Mime-Version: 1.0 Reply-To: dchamberlinNOSPAM@dlawton.com Newsgroups: borland.public.jbuilder.java.language