Article View: borland.public.jbuilder.java.language
Article #17503Dynamic method binding
From: Vishal P Mahabeer
Date: Thu, 05 Nov 1998 00:00
Date: Thu, 05 Nov 1998 00:00
22 lines
1144 bytes
1144 bytes
Hi.
Consider the following extract of code:
1 public void addToDict (String key, Object value) {
2 dict.put (key, value); //dict is an instance of Hashtable
3 value.setController (this);
4 }
In Line 1 (Object value): I want this to be a place holder for an object
that can be one of several classes. Therefore, Line 3
(value.setController) should invoke the method setController on whatever
the 'value' object turns out to be. The reason I use Object value in Line
1 is that at compile time I do not yet know what that object will be, and
it may change from one invocation to another.
Is there a way to allow the method to dynamically be invoked on the 'value'
object?
Thanks
Vishal
vishal.mahabeer@ddbs.co.za
Technical Details
Message-ID:
<01be08c8$d3d2edd0$c60924c4@vishalm>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,db2d30fe5814e4cb,start X-Google-Attributes: gidf74b3,public From: "Vishal P Mahabeer" <vishalm@spl.co.za> Subject: Dynamic method binding Date: 1998/11/05 Message-ID: <01be08c8$d3d2edd0$c60924c4@vishalm> X-Deja-AN: 408668342 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language