---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 15 Edition"
java_version: 15
chapter: "Chapter 6. The Java Virtual Machine Instruction Set"
section: "6.5.getfield"
heading: "getfield"
parent: "6.5. Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se15/html/jvms-6.html#jvms-6.5.getfield
id: "6.5.getfield"
url: https://jvm.obfuscated.software/jvms/se15/6.5.getfield.html
raw: https://jvm.obfuscated.software/jvms/se15/6.5.getfield.md
---

# getfield

## Operation

Fetch field from object

## Format

```
getfield
indexbyte1
indexbyte2
```

## Forms

*getfield* = 180 (0xb4)

## Operand Stack

..., *objectref* →

..., *value*

## Description

The unsigned *indexbyte1* and *indexbyte2* are used to construct an index into the run-time constant pool of the current class ([§2.6](2.6.md)), where the value of the index is (*indexbyte1* `<<` 8) | *indexbyte2*. The run-time constant pool entry at the index must be a symbolic reference to a field ([§5.1](5.1.md)), which gives the name and descriptor of the field as well as a symbolic reference to the class in which the field is to be found. The referenced field is resolved ([§5.4.3.2](5.4.3.2.md)).

The *objectref*, which must be of type `reference` but not an array type, is popped from the operand stack. The *value* of the referenced field in *objectref* is fetched and pushed onto the operand stack.

## Linking Exceptions

During resolution of the symbolic reference to the field, any of the errors pertaining to field resolution ([§5.4.3.2](5.4.3.2.md)) can be thrown.

Otherwise, if the resolved field is a `static` field, *getfield* throws an `IncompatibleClassChangeError`.

## Run-time Exception

Otherwise, if *objectref* is `null`, the *getfield* instruction throws a `NullPointerException`.

## Notes

The *getfield* instruction cannot be used to access the `length` field of an array. The *arraylength* instruction ([§*arraylength*](6.5.arraylength.md)) is used instead.
