---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 19 Edition"
java_version: 19
chapter: "Chapter 4. The class File Format"
section: "4.10.1.9.getfield"
heading: "getfield"
parent: "4.10.1.9. Type Checking Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se19/html/jvms-4.html#jvms-4.10.1.9.getfield
id: "4.10.1.9.getfield"
url: https://jvm.obfuscated.software/jvms/se19/4.10.1.9.getfield.html
raw: https://jvm.obfuscated.software/jvms/se19/4.10.1.9.getfield.md
---

# getfield

A *getfield* instruction with operand `CP` is type safe iff `CP` refers to a constant pool entry denoting a field whose declared type is `FieldType`, declared in a class `FieldClassName`, and one can validly replace a type matching `FieldClassName` with type `FieldType` on the incoming operand stack yielding the outgoing type state. `FieldClassName` must not be an array type. `protected` fields are subject to additional checks ([§4.10.1.8](4.10.1.8.md)).

```
instructionIsTypeSafe(getfield(CP), Environment, _Offset, StackFrame,
                      NextStackFrame, ExceptionStackFrame) :-
    CP = field(FieldClassName, FieldName, FieldDescriptor),
    parseFieldDescriptor(FieldDescriptor, FieldType),
    passesProtectedCheck(Environment, FieldClassName, FieldName,
                         FieldDescriptor, StackFrame),
    currentClassLoader(Environment, CurrentLoader),
    validTypeTransition(Environment,
                        [class(FieldClassName, CurrentLoader)], FieldType,
                        StackFrame, NextStackFrame),
    exceptionStackFrame(StackFrame, ExceptionStackFrame).
```
