O'Reilly logo

The Java® Language Specification, Java SE 7 Edition, Fourth Edition by Alex Buckley, Gilad Bracha, Guy Steele, Bill Joy, James Gosling

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.8. Class Objects for Arrays

Every array has an associated Class object, shared with all other arrays with the same component type.

Example 10.8-1. Class Object Of Array

class Test {    public static void main(String[] args) {        int[] ia = new int[3];        System.out.println(ia.getClass());        System.out.println(ia.getClass().getSuperclass());    }}

This program produces the output:

class [Iclass java.lang.Object

where the string “[I” is the run-time type signature for the class object “array with component type int”.

Example 10.8-2. Array Class Objects Are Shared

class Test {    public static void main(String[] args) {        int[] ia = new int[3];        int[] ib = new int[6];        System.out.println(ia.getClass() == ib.getClass()); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required