当前位置:网站首页>如何获取泛型的类型
如何获取泛型的类型
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();
}
}
}
}边栏推荐
- 3. seat number
- day31 js笔记 DOM下 2021.09.26
- Characteristics of solar wireless LED display
- Fruit FL studio/cubase/studio one music host software comparison
- Multi dimensional monitoring: the data base of intelligent monitoring
- 2018 joint examination of nine provinces & Merging of line segment trees
- day29 js笔记 2021.09.23
- Build your own website (18)
- Solutions to connection failures and errors when accessing mysql8 using the SSM project
- ProCAST finite element casting process simulation software
猜你喜欢

Data analysis learning notes

Remote login sshd service

day30 js笔记 BOM和DOM 2021.09.24

【C语言】二叉树的实现及三种遍历

Using soapUI to obtain freemaker's FTL file template

Characteristics of solar wireless LED display

Day30 JS notes BOM and DOM 2021.09.24

纯纯大怨种!那些年被劝退的考研专业

Prefix and (2D)

Prepare for Jin San Yin Si I. testers without experience in automated testing projects should look at it quickly
随机推荐
Is it safe to buy stocks and open an account on the account QR code of the CICC securities manager? Ask the great God for help
day28 严格模式、字符串 js 2021.09.22
Daily practice of C language - day 3: calculate the number of occurrences of sub strings of strings
MySQL cannot query the maximum value using the max function
Simple understanding of ThreadLocal
Unity screenshot function
AcWing 609. Salary (implemented in C language)
【C语言】二叉树的实现及三种遍历
JS foundation 8
Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration
For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?
Day37 JS note motion function 2021.10.11
零基础C语言(一)
水果FL Studio/Cubase/Studio one音乐宿主软件对比
AcWing 608. Poor (implemented in C language)
Dongyuhui, New Oriental and Phoenix Satellite TV
Open3d manual clipping point cloud
Build your own website (18)
Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush
Day28 strict mode, string JS 2021.09.22