On Thu, 28 Oct 1999, Thomas McKay wrote:

It just is. This was the biggest and most difficult change made when
moving from the 1.0 to 1.1 version. My paper from the Tcl 98 conf
goes into more detail about it. See
http://www-users.cs.umn.edu/~dejong/tcl/paper.html section 5.1 for
a good description.
 
> Ahh, I remember hearing this from you in the past.  However, as then, I
> still don't get why it's bad to use the "most derived" class.  Why wouldn't
> you want to give the user access to the DerivedFromHashtable (to use the
> example in the docs)?

If you want to provide a class as a type, then do so.

ReflectObject.newInstance( interp, MostDerived.class , this );

Using getClass() is not a safe thing to do in the general case.
In some cases it will do what you expect, but in others it will not.
Therefore, the best "general" solution is to always use NAME.class.

later
mo

>  What if there are methods or fields in this derived
> class that you'd like to provide for the user?  Is it simply a matter of
> security or integrity of the object or what?
> 
> The call to ReflectObject.newInstance() in my case is in a base class that
> is then extended by other similar classes.  What would be the difference
> between putting
> 
>       ReflectObject.newInstance( interp, this.getClass(), this );
> 
> in the higher level class where this.getClass() resolved to the subclass and
> putting
> 
>       ReflectObject.newInstance( interp, SubClass.class );
> 
> calls in each of the subclasses?
> 
> > ACK, NO! Do not call this.getClass() to get the second argument
> > to the ReflectObject.newInstance() method. You need to use the
> > actual Java Class object that the instance will be reflected as.
> > For instance if you want to reflect a java.lang.String object
> > you need to call it like the following example. Using getClass()
> > seems like a good idea but you will end up shooting yourself in the foot.
> > See the docs for ReflectObject.newInstance() if you want a
> > detailed example of why that is so very wrong.
> >
> > obj = ReflectObject.newInstance( interp, String.class, "my string" );
> >
> >
> > >             tclObject = ReflectObject.newInstance( interp,
> > >                      this.getClass(), this );
> > >             tclObject.preserve();
> >>
> 

----------------------------------------------------------------
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]'. 

Reply via email to