当前位置:网站首页>如何获取泛型的类型
如何获取泛型的类型
2022-06-28 11:38:00 【一杯苦芥】
@Override
public void loadImage(@NonNull Context context, @Nullable String url, @Nullable Options options, @Nullable ILoaderListener<T> listener) {
Type type = listener.getClass().getGenericInterfaces()[0];
//若type是ParameterizedType的实例, 则强转,ParameterizedType可以得到泛型的类型
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) type;
Type[] types = pType.getActualTypeArguments();
if (types != null && types.length > 0) {
Class clazz = (Class) types[0];
try {
Log.e("test", types[0].equals(Drawable.class));
Log.e("test", clazz.equals(Drawable.class));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}边栏推荐
- Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
- 携手Cigent:群联为SSD主控固件引入高级网络安全防护特性
- ArrayList源码解析
- Day29 JS notes 2021.09.23
- Intranet penetration in the working group environment: some basic methods
- js中的class类模式及语法 2021.11.10
- Open3d manual clipping point cloud
- 5. Sum of N numbers
- Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
- On the output representation of bidirectional LSTM in pytoch
猜你喜欢

How to deploy the software testing environment?

Convert black mask picture to color annotation file

水果FL Studio/Cubase/Studio one音乐宿主软件对比

Class pattern and syntax in JS 2021.11.10

Graphics view framework for QT learning (to realize startup animation)

Unity screenshot function

New listing of operation light 3.0 - a sincere work of self subversion across the times!

Day29 JS notes 2021.09.23

day36 js笔记 ECMA6语法 2021.10.09

Build your own website (18)
随机推荐
day30 js笔记 BOM和DOM 2021.09.24
IO stream of file and Base64
水果FL Studio/Cubase/Studio one音乐宿主软件对比
What is the main chain system?
Ali three sides: what is the difference between using on or where in the left join associated table and the condition
Unity screenshot function
建立自己的网站(18)
Django -- MySQL database reflects the mapping data model to models
Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
Day24 JS notes 2021.09.15
day31 js笔记 DOM下 2021.09.26
Setinterval, setTimeout and requestanimationframe
Simple understanding of ThreadLocal
Using soapUI to obtain freemaker's FTL file template
Day39 prototype chain and page fireworks effect 2021.10.13
Using MySQL database in the express framework of node
来吧元宇宙,果然这热度一时半会儿过不去了
Simulation of the Saier lottery to seek expectation
Data analysis learning notes
ArrayList源码解析