The java::field Command


java::field ?-noconvert? objOrClass field ?value field value ...?

The java::field command is used to manipulate accessible fields from Tcl. The objOrClass argument specifies either a fully qualified name of the declaring class of the field to access, or an object handle. The field argument specifies which field to manipulate. If an additional value parameter exists, then the field will be set to value, otherwise the current value of the field is returned. Multiple fields may be set via additional parameters by alternating field signatures and values. To access a shadowed field in a superclass, a full field signature consisting of the field name followed by the superclass name must be provided as the field argument.


The java::field command can be used to get the value of a static class variable. In this example, we query the static variable java.lang.Integer.MAX_VALUE, which has the value 2147483647.

% java::field Integer MAX_VALUE

The java::field command can be used to set the value of an instance field. In this example, it is assumed that the class APublic has a public java.lang.String field named foo. The value is queried after being set.

% set obj [java::new APublic]
% java::field $obj foo bar
% java::field $obj foo

The java::field command also supports getting the compiler simulated class field for a Class. This is the preferred method of getting a handle to a java.lang.Class object given a class name.

% set cl [java::field java.util.Hashtable class]
% java::info class $cl

Copyright © 1997-1998 Sun Microsystems, Inc.