Android 开发问题:Raw use of parameterized class ‘Class‘

java 复制代码
private void doSendBroadcast(Context context, Class cls) {
    Intent intent = new Intent(context, cls);
    context.sendBroadcast(intent);
}
  • 在 Android 开发中,上述代码出现如下警告信息

    Raw use of parameterized class 'Class'

问题原因
  • 使用了原生类型 Class,而没有提供泛型参数,Class 本身是一个泛型类 Class<T>
处理策略
  • 提供泛型参数
java 复制代码
private void doSendBroadcast(Context context, Class<? extends BroadcastReceiver> cls) {
    Intent intent = new Intent(context, cls);
    context.sendBroadcast(intent);
}
相关推荐
橙子圆1232 小时前
SpringMVC5.0
java·spring·servlet
黄林晴2 小时前
根治协程陋习!官方级协程Skill发布
android·kotlin
绿草在线2 小时前
02. JakartaEE11+Thymeleaf实现图书管理模块
java
胡图图不糊涂^_^2 小时前
网络原理笔记
java·网络·笔记·学习·tcp/ip·http·https
嘻嘻哈哈樱桃2 小时前
牛客经典101题题解集--哈希
java·数据结构·python·算法·leetcode·职场和发展·哈希算法
SamDeepThinking2 小时前
秒杀系统里的RocketMQ,不是发个消息那么简单
java·后端·架构
卷毛的技术笔记2 小时前
告别“盲猜式”排障:分布式链路追踪方案选型与Spring Boot 3实战
java·spring boot·分布式·后端·spring·面试·系统架构
XiYang-DING2 小时前
【Java EE】线程池
java·开发语言·java-ee
浪客川2 小时前
UniFFI 跨平台开发Rust 与 Android (Kotlin) 集成
android·rust·kotlin