Language syntax

Object alias and lifetime

Two references can address the same heap object; method scope does not determine object lifetime.

Formal Syntax & Structure

java syntaxjava
int[] alias = first

Working Example

Example Snippetjava
public class Main {    static int[] make() { return new int[]{3, 5}; }    public static void main(String[] args) throws Exception {        int[] first = make();        int[] alias = first;        alias[0] = 9;        System.out.println(first[0]);    }}
Java Reference