---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 12 Edition"
java_version: 12
chapter: "Chapter 5. Conversions and Contexts"
section: "5.3"
heading: "5.3. Invocation Contexts"
parent: "Chapter 5. Conversions and Contexts"
source: https://docs.oracle.com/javase/specs/jls/se12/html/jls-5.html#jls-5.3
id: "5.3"
url: https://jvm.obfuscated.software/jls/se12/5.3.html
raw: https://jvm.obfuscated.software/jls/se12/5.3.md
---

# 5.3. Invocation Contexts

*Invocation contexts* allow an argument value in a method or constructor invocation ([§8.8.7.1](8.8.7.1.md), [§15.9](15.9.md), [§15.12](15.12.md)) to be assigned to a corresponding formal parameter.

*Strict* invocation contexts allow the use of one of the following:

- an identity conversion ([§5.1.1](5.1.1.md))
- a widening primitive conversion ([§5.1.2](5.1.2.md))
- a widening reference conversion ([§5.1.5](5.1.5.md))

*Loose* invocation contexts allow a more permissive set of conversions, because they are only used for a particular invocation if no applicable declaration can be found using strict invocation contexts. Loose invocation contexts allow the use of one of the following:

- an identity conversion ([§5.1.1](5.1.1.md))
- a widening primitive conversion ([§5.1.2](5.1.2.md))
- a widening reference conversion ([§5.1.5](5.1.5.md))
- a widening reference conversion followed by an unboxing conversion
- a widening reference conversion followed by an unboxing conversion, then followed by a widening primitive conversion
- a boxing conversion ([§5.1.7](5.1.7.md))
- a boxing conversion followed by widening reference conversion
- an unboxing conversion ([§5.1.8](5.1.8.md))
- an unboxing conversion followed by a widening primitive conversion

If, after the conversions listed for an invocation context have been applied, the resulting type is a raw type ([§4.8](4.8.md)), an unchecked conversion ([§5.1.9](5.1.9.md)) may then be applied.

A value of the null type (the null reference is the only such value) may be assigned to any reference type.

It is a compile-time error if the chain of conversions contains two parameterized types that are not in the subtype relation ([§4.10](4.10.md)).

If the type of an argument expression is either `float` or `double`, then value set conversion ([§5.1.13](5.1.13.md)) is applied after the conversion(s):

- If an argument value of type `float` is an element of the float-extended-exponent value set, then the implementation must map the value to the nearest element of the float value set. This conversion may result in overflow or underflow.
- If an argument value of type `double` is an element of the double-extended-exponent value set, then the implementation must map the value to the nearest element of the double value set. This conversion may result in overflow or underflow.

The only exceptions that may arise in an invocation context are:

- A `ClassCastException` if, after the type conversions above have been applied, the resulting value is an object which is not an instance of a subclass or subinterface of the erasure ([§4.6](4.6.md)) of the corresponding formal parameter type.
- An `OutOfMemoryError` as a result of a boxing conversion.
- A `NullPointerException` as a result of an unboxing conversion on a null reference.

Neither strict nor loose invocation contexts include the implicit narrowing of integer constant expressions which is allowed in assignment contexts. The designers of the Java programming language felt that including these implicit narrowing conversions would add additional complexity to the rules of overload resolution ([§15.12.2](15.12.2.md)).

Thus, the program:

```
class Test {
    static int m(byte a, int b) { return a+b; }
    static int m(short a, short b) { return a-b; }
    public static void main(String[] args) {
        System.out.println(m(12, 2));  // compile-time error
    }
}
```

causes a compile-time error because the integer literals `12` and `2` have type `int`, so neither method `m` matches under the rules of overload resolution. A language that included implicit narrowing of integer constant expressions would need additional rules to resolve cases like this example.
