일반 객체 가져오기

1595 단어
package com.wanggs.com.wanggs.json.fastjson.test;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by wanggs on 2017/7/27.
 *        
 */
public class Father {
    public Father() {
        System.out.println("Father.Father" + this);
       Class clazz = this.getClass();// Son
        ParameterizedType type = (ParameterizedType) clazz.getGenericSuperclass();// Father
        Type[] types = type.getActualTypeArguments();
        Class paramClass = (Class) types[0];
        System.out.println(paramClass);
        // class com.wanggs.com.wanggs.json.fastjson.test.Dog

/**
Type genType = getClass().getGenericSuperclass();
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
        entityClass = (Class) params[0];
        System.out.println(entityClass);
*/

        

        //   
      /*  Class clazz;
        ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();

        clazz = (Class) type.getActualTypeArguments()[0];*/
    }
}

class Son extends Father {
    public Son() {
        System.out.println("Son = " + this);
    }

}

class Dog {

}

class Test {
    public static void main(String[] args) {
        Son son = new Son();
        // Father.Fathercom.wanggs.com.wanggs.json.fastjson.test.Son@6e0be858
        //  Son = com.wanggs.com.wanggs.json.fastjson.test.Son@6e0be858

        // Father father = new Father();
        //Father.Fathercom.wanggs.com.wanggs.json.fastjson.test.Father@61bbe9ba

    }
}

좋은 웹페이지 즐겨찾기