java-Reflex-getgenericsuperclass ()

Source: Internet
Author: User

1PublicClass person<t> {29 ·45Import Java.lang.reflect.ParameterizedType;6Import Java.lang.reflect.Type;78PublicClass StudentExtendsperson<student> {9PublicStaticvoid Main (string[] args) {Ten Student st=New Student ();One Class clazz=st.getclass ();12//Getsuperclass () Gets the parent class of the classSystem.out.println (Clazz.getsuperclass ());14//Getgenericsuperclass () Gets the parent class with the generic type15//Type is the public advanced interface for all types in the Java programming language. They include primitive types, parameterized types, array types, type variables, and base types.Type=clazz.getgenericsuperclass Type ();System.out.println (type);18//Parameterizedtype parameterized type, which is genericParameterizedtype p= (parameterizedtype) type;20//getactualtypearguments get an array of parameterized types, generics may have multiple 21 Class c= (Class) P.getactualtypearguments () [0]; System.out.println (c); 23} 24} 25 26 print result: 27 28 class com. test. person29 com.test. Person<com.test. student>30 class com.test. Student 

Java-Reflection-getgenericsuperclass ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.