Home » Java programming language

Java Class class getTypeParameters() method with example

Class class getTypeParameters() method: Here, we are going to learn about the getTypeParameters() method of Class class with its syntax and example.
Submitted by Preeti Jain, on November 23, 2019

Class class getTypeParameters() method

  • getTypeParameters() method is available in java.lang package.
  • getTypeParameters() method is used to return an array of TypeVariable that denotes the variable type declared by the generic representation of this GenericDeclaration.
  • getTypeParameters() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getTypeParameters() method may throw an exception at the time of returning parameter types.
    GenericSignatureFormatError: This exception may raise when the generic signature of this generic declaration does not match to the format given in the JVM Specification.


    public TypeVariable[] getTypeParameters();


  • It does not accept any parameter.

Return value:

The return type of this method is TypeVariable[], it returns the following value based on the given cases,

  • It returns an array of TypeVariable that denotes the variable type defined by the generic declaration.
  • It returns 0, when the underlying generic declaration defines no variable type.


// Java program to demonstrate the example 
// of TypeVariable[]  getTypeParameters () method of Class 

import java.util.*;
import java.lang.reflect.*;

public class GetTypeParametersOfClass {
 public static void main(String[] args) throws Exception {
  // It returns the array of TypeVariable represented by the 
  //class ArrayList
  TypeVariable[] type_var = ArrayList.class.getTypeParameters();

  for (int i = 0; i < type_var.length; ++i) {
   System.out.print("TypeVariable of ArrayList: " + " ");


TypeVariable of ArrayList:  E


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.