Mo DeJong wrote:
> It depends on what you are doing. In regular Java, you need to know
> what the type of the objects you put into a vector are because
> you need to cast them back up to something when you pull them
> out of the vector. TclJava is no different, you just put the
> class you would cast to as the argument to newInstance().
Yes, in Java, I need to know the class of an object in a vector, so I can cast it back
to that class if I need to call any of that class's methods. getClass() tells me
exactly
that. So if that is incorrect in TclBlend, there must be something else going on.
> There is one in the documentaiton for ReflectObject.
>
> http://dev.scriptics.com/man/java1.2.6/TclJavaLib/ReflectObject.htm
I am familiar with that illustration, but all it says is that "the reflection system
will not work as expected and you could introduce serious security bugs into your
program." It is not specific about the harmful effects. This is where a clearer example
would be of great help, I think. (At least to me, and probably to others, since I've
seen other questions on the web about this issue.)
> Note how the example class would be reflected as the wrong type.
>
> Here is another example:
>
> import java.util.Hashtable;
> public class Hashtable2 extends Hashtable
> {
> public static Hashtable get() {
> return new Hashtable2();
> }
> public void NEVER_CALL() {
> System.out.println("NEVER_CALL");
> }
> }
>
> % set h [java::call Hashtable2 get]
>
> ( Here is what would happen if you called getClass() )
> % java::info class $h
> Hashtable2
>
> This means you would be able to invoke "$h NEVER_CALL"
> which is not possible from regular Java code.
I vaguely see what you're driving at, but this example doesn't call
ReflectObject.newInstance() at all, so I'm not clear on how it applies to the
discussion. If h is set, not by calling a static method that does a Java new, but by
calling a Tcl extension that does a ReflectObject.newInstance(), then I would in fact
expect exactly that NEVER_CALL should be accessible via h, since the class of h is
Hashtable2.
Mo, I'm sure you are frustrated at having to explain this over and over again, and I
apologize for being dense, but I am just not getting it. I think part of the confusion
stems from your use of the phrase "its most derived type." The only type that is not
"derived" from some other (I assume you mean extended) is Object, so all the guidance I
can deduce from that is to always specify Object in the ReflectObject.newInstance()
call.
----------------------------------------------------------------
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