On Fri, 23 Jun 2000, Frank Krahmer wrote:
> Dear Sir,
>
> how can I access a public baseclass attribute in a Java class via Jacl,
> when an object of derived class is instanciated ?
>
> Java-class example :
> --------------------
> public class baseClass
> { public String dummyAttribute;
> }
> public class derivedClass extends baseClass
> { // anything
> }
>
> Jacl-access example :
> ---------------------
> set theDerivedObj [java::new derivedClass]
> java::field $theDerivedObj dummyAttribute "blabla" // RUNTIME ERROR
> // brings error tcl.lang.TclException: field "name" doesn't exist
I did a detailed analysis of this problem, and it looks
like it is going to be very hard to solve properly. This
is basically the same problem that is solved by the
runtime method resolver I added to tcljava.
When you start walking up the inheritance tree looking
for fields that match, you also have to watch out for
all the strange edge cases like ambiguous field
signatures caused by an interface that also defines
a field with the same name and so on.
In the mean time, I have included a "quick and dirty"
patch that will make your test case work. This patch
actually breaks a couple of other things in the
test suite so it is not going to be checked in, but
you can use it on your own tree. The "real" fix
is going to take some time to implement, and I
am not going to be able to get to it for at least
a month.
Mo DeJong
Red Hat Inc
Index: src/tcljava/tcl/lang/FieldSig.java
===================================================================
RCS file: /home/cvs/external/tcljava/src/tcljava/tcl/lang/FieldSig.java,v
retrieving revision 1.2
diff -u -r1.2 FieldSig.java
--- FieldSig.java 1999/05/09 21:19:41 1.2
+++ FieldSig.java 2000/06/23 21:47:35
@@ -157,7 +157,7 @@
}
try {
- field = sigCls.getDeclaredField(fieldName);
+ field = sigCls.getField(fieldName);
} catch (NoSuchFieldException e) {
throw new TclException(interp, "field \"" + signature +
"\" doesn't exist");
----------------------------------------------------------------
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