---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 27 Edition"
java_version: 27
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/se27/html/jvms-4.html#jvms-4.10.1.9.getfield
id: "4.10.1.9.getfield"
url: https://jvm.obfuscated.software/jvms/se27/4.10.1.9.getfield.html
raw: https://jvm.obfuscated.software/jvms/se27/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` that is a member of a type `FieldClassType`, and one can validly replace `FieldClassType` with `FieldType` on the incoming operand stack yielding the outgoing type state. `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(FieldClassType, FieldName, FieldDescriptor),
    parseFieldDescriptor(FieldDescriptor, FieldType),
    passesProtectedCheck(Environment, FieldClassType, FieldName,
                         FieldDescriptor, StackFrame),
    validTypeTransition(Environment, [FieldClassType], FieldType,
                        StackFrame, NextStackFrame),
    exceptionStackFrame(StackFrame, ExceptionStackFrame).
```
