Close

Java Reflection - Class.getComponentType() Examples

Java Reflection Java Java API 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public Class<?> getComponentType()

Returns the Class representing the component type of an array. If this class does not represent an array class this method returns null.

Returns:
the Class representing the component type of this class if this class is an array


Examples


package com.logicbig.example.clazz;

public class GetComponentTypeExample {

public static void main(String... args) {
int[] ints = {};
System.out.println(ints.getClass().getComponentType());

System.out.println(String[].class.getComponentType());

Void[] voids = {};
System.out.println(voids.getClass().getComponentType());

System.out.println(String.class.getComponentType());
}
}

Output

int
class java.lang.String
class java.lang.Void
null




See Also