On Thu, 28 Oct 1999, Thomas McKay wrote:
> How would I do it in Java? This is what I have now...
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();
It should be.
> Would it be as simple as
>
> interp.renameCommand( tclObject.toString(), "rect20" );
Yes, this is a side effect (meaning a bug) of the current implementation.
You should be able to call interp.renameCommand("rect20" , "") to delete
the command. You will still need to call release() which would be the
same as the "unset o" in my example.
later
mo
> Would I have to do an equivalent "rename rect20 {}" when I called
>
> tclObject.release();
>
> >
> > % set o [java::new Object]
> > java0x1
> > % $o toString
> > java.lang.Object@80d05fd
> > % rename $o rect20
> > % rect20 toString
> > java.lang.Object@80d05fd
> >
> > The catch is that you need to delete this renamed object like so.
> > % rename rect20 {}
> > % unset o
> > > >
>
----------------------------------------------------------------
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]'.