set value of static field
Bytecode
Type | Description |
u1 | putstatic opcode = 0xB3 (179) |
u2 | index |
Stack ..., value => ... OR ..., value.word1, value.word2 => ...
Description
putstatic sets the value of the static field (also known as a class field) identified by <field-spec> to the single or double word value on the operand stack. For example, when you write the Java expression:
java.lang.System.out = myStream;
this generates a call to getstatic like:
aload_1 ; push object reference in local variable 1 (i.e. myStream) onto stack ; now use putstatic to assign it to System.out putstatic java/lang/System/out Ljava/io/PrintStream;
The unsigned index is used to point to field entry, a reference to a class name
and a field name. If the field is protected
, then it must be either a member
of the current class or a member of a superclass of the current class.
The constant pool item is resolved, determining both the class field and its width. The
type of a value stored by a putstatic instruction must be compatible with
the descriptor of the field of the class instance being stored into. If the field
descriptor type is byte
, char
, short
, or int
,
then the value must be an int
. If the field descriptor type is float
,
long
, or double
, then the value must be a float
,
long
, or double
, respectively. If the field descriptor type is a
reference type, then the value must be of a type that is assignment compatible with
the field descriptor type.
The value is popped from the operand stack, and the class field is set to value.