---
title: "java泛型  参数化类型"
author: "yangbinfx"
date: "2021-02-22T18:22:06Z"
tags: []
categories: ["移动开发"]
slug: "java"
draft: false
lastmod: "2021-02-22T18:22:06Z"
id: 2519261
url: "https://yangbinfx.iteye.com/blog/2519261"
---

```
private Map<String, Number> collection;
     
    public static void main(String[] args) throws  Exception{
            Class<?> clazz = TestgetGenericType.class; //取得 Class
            Field field = clazz.getDeclaredField("collection"); //取得字段变量
            Type type = field.getGenericType(); //取得泛型的类型
            ParameterizedType ptype = (ParameterizedType)type; //转成参数化类型
            System.out.println(ptype.getActualTypeArguments()[0]); //取出第一个参数的实际类型
            System.out.println(ptype.getActualTypeArguments()[1]); //取出第二个参数的实际类型
    }
 
}
```