Having one command that does two totally unrelated things seems
like a bad design if you ask me. It might be cleaner to define
a command to invoke the static method and another one to actually
do the shorter cast operation. What if you used something like this?
set s [java::new String "I am a Java String"]
# This will cast a String to an Object
set o [(Object) $s]
# Or like this
set o [(Object) [java::new String "I am a Java String"]]
It could be defined like this.
proc (Object) { o } {
return [java::cast Object $o]
}
You could create a bunch of these like so.
foreach type {Object String Integer} {
proc ($type) { o } "return \[java::cast $type \$o\]"
}
> The per-class command is actually implemented in Java. It checks
> if it has been invoked with one argument and, if so, if this
> argument refers to a reflected java object. If so, it implements
> casting behaviour, otherwise it attempts to call a static method.
>
> > Could you provide some more info about what additional
> > features your changes will provide and the pros and cons
> > of your modifications?
So the main feature is to avoid using java::call? I guess that
might help. I am not so sure about this argument when applied
to java::cast. I think the java::cast command is straightforward
but I could be biased because I wrote it:)
> The main feature is a (potentially substantial) improvement in
> the tidyness of TclJava code which uses large numbers of casts
> and static methods. It's possible that there could also be a
> speed improvement given a clever implementation, but this would
> be minor -- code clarity is the main aim.
>
> Against, it means creating more commands in the Tcl interpretter
> (although any serious TclJava application will have quite a few
> object-reflection commands anyway).
I guess overloading the command to do casting and calling is
my main problem with your suggestion. Overloading things seems
like a great idea, but it leads to confused users in the long
run (C++ proves this point much better than I even could).
later
Mo DeJong
> You might also argue that
> having a single command which can be used both for casting and
> calling static methods is a little confusing (but it seems to work
> quite well in practice).
>
> Thomas.
----------------------------------------------------------------
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]'.