The StaticField probe object

The StaticField probe object inserts a new static field into every probed Java class. This static field is accessible to probe fragments, and can be used to store information inside probed classes.

The term "static field" refers to a field of the class which is declared static. This is sometimes called a "static variable", a "class field", or a "class variable" (versus an "instance variable").

The StaticField object is optional.

The StaticField object has the following property:
Property Description
type Required. The type property specifies the Java type string for the new field. The string must be a fully-qualified Java class name. For example: java.lang.StringBuffer. The type string must represent an ordinary class type, not a primitive type or an array type. The named class must have a default constructor that takes no arguments, which is accessible to the probed class.
When you use a StaticField object, the new static field is initialized in the probed class by calling the default constructor for its type; similar to adding the following source code to the class at class scope:
static private type fieldName = new type();

The initialization call is made at the start of the class initializer for the probed class. If the class does not have a class initializer, one will be created. If the probe has a StaticInitializer fragment, the StaticInitializer fragment code will execute after the static field has been constructed.

Probe fragments can use the staticField data item to access the object referenced by the static field. Fragments can change the state of the object that the static field refers to, but they cannot make the static field refer to a different object.

A probe can have only one StaticField object. To use StaticField to store more than one item in the probed class, use a composite object type such as ArrayList, HashMap, or HashSet, or define and use a new class with the data structure you need.

Example
<staticField type="java.util.Date" />
<fragment type="staticInitializer">
   <data type="staticField" name="lastInstanceDate" />
   <code>
      . . . 
   </code>
</fragment>

Contained by
The Probe object

Parent topic: Probekit element reference

Related reference
The Data probe object

Related information
staticField and staticInitializer example

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.