---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 21 Edition"
java_version: 21
chapter: "Chapter 8. Classes"
section: "8.4.5"
heading: "8.4.5. Method Result"
parent: "8.4. Method Declarations"
source: https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-8.4.5
id: "8.4.5"
url: https://jvm.obfuscated.software/jls/se21/8.4.5.html
raw: https://jvm.obfuscated.software/jls/se21/8.4.5.md
---

# 8.4.5. Method Result

The *result* of a method declaration either declares the type of value that the method returns (the *return type*), or uses the keyword `void` to indicate that the method does not return a value.

```
Result:
  UnannType
  void
```

If the result is not `void`, then the return type of a method is denoted by *UnannType* if no bracket pairs appear after the formal parameter list, and is specified by [§10.2](10.2.md) otherwise.

Return types may vary among methods that override each other if the return types are reference types. The notion of return-type-substitutability supports *covariant returns*, that is, the specialization of the return type to a subtype.

A method declaration `d_1` with return type R_1 is *return-type-substitutable* for another method `d_2` with return type R_2 iff any of the following is true:

- If R_1 is `void` then R_2 is `void`.

- If R_1 is a primitive type then R_2 is identical to R_1.

- If R_1 is a reference type then one of the following is true:

  - R_1, adapted to the type parameters of `d_2` ([§8.4.4](8.4.4.md)), is a subtype of R_2.
  - R_1 can be converted to a subtype of R_2 by unchecked conversion ([§5.1.9](5.1.9.md)).
  - `d_1` does not have the same signature as `d_2` ([§8.4.2](8.4.2.md)), and R_1 = |R_2|.

An unchecked conversion is allowed in the definition, despite being unsound, as a special allowance to allow smooth migration from non-generic to generic code. If an unchecked conversion is used to determine that R_1 is return-type-substitutable for R_2, then R_1 is necessarily not a subtype of R_2 and the rules for overriding ([§8.4.8.3](8.4.8.3.md), [§9.4.1](9.4.1.md)) will require a compile-time unchecked warning.
