On Thu, 29 Jun 2000, Thomas McKay wrote:

> But let's assume that I do indeed want the most derived class.

Seems kind of dangerous, but Ok.

> If I change this.getClass() to DbObj.getClass(), then the Tcl objects
> returned from this method will only have DbObj's methods and fields exposed,
> right?

Right.
 
> This is, however, a utility method and I don't want to force every single
> object that will eventually be added to the system to copy this code simply
> to replace the "DbObj.getClass()" with "ExtendedDbObj.getClass()".
> 
> I *want* ExtendedDbObj's (and all other classes' derived from DbObj) methods
> and fields exposed.  Yes, even in the case of C -> D -> E -> F -> G.
> 
> Now, given that... what is fatal about this.getClass()?  If it simply the
> case that the user would have to explicitly use a method signature for
> java::call, that's fine with me.  If it means that their extension might
> break my Tcl code, I see your point and agree... but is it programatically
> *fatal*.

Well, no there is nothing fatal about it, it just means your code could
be broken by someone extending one of your classes in a way you did not
expect.

> Let's say that I do change this.getClass() to DbObj.getClass().  Would this
> mean that
> 
> % set obj [some-func-to-get-an-extended-object]
> java0x8a
> % $obj someExtendedFunc
> 
> would change to
> 
> % set obj [some-func-to-get-an-extended-object]
> java0x8a
> % set eobj [java::cast ExtendedDbObj $obj]
> % $eobj someExtendedFunc

The java::cast call would do the same thing as passing ExtendedDbObj.class
to ReflectObject.newInstance(). It is not exactly the same because in
the case of a cast you know the name of the class you expect it to
be. You do not know what getClass() will return unless you make your
class final so that it can not be extended.

> If that's the case, I agree with you completely that from a long-term
> perspective it would be better for me to call DbObj.getClass().  Hmmm....
> sounds like I've convinced myself you're right.

You might be able to come up with a case where getClass() does
what you want, but if everyone called getClass() everywhere
without realizing how it could hose things up, that would
be bad.

Mo DeJong
Red Hat Inc

----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com

Reply via email to