android - 是否可以将类 <protocol> 作为参数传递?

标签 android android-intent

实际上,我想创建一个能够处理多种类型的 ArrayList 的函数。

public void someFunction(Class ArrayList<protocol>) {
    ArrayList<?> object = new ArrayList<protocol>;
}

类似的,有什么建议吗?

最佳答案

可能对你有帮助

public class TestClass {

    public void function(List<? extends Object> temp){

        ArrayList<? extends Object> obj=(ArrayList<? extends Object>) temp;


        }
}

然后你可以使用不同类型的参数以这种方式调用这个函数。

        TestClass test= new TestClass();

        test.function(new ArrayList<String>());
        test.function(new ArrayList<Integer>());
        test.function(new ArrayList<TestClass>());

关于android - 是否可以将类 <protocol> 作为参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16978126/

相关文章:

java - 两个日期之间的差异?

android - 错误类型 3 : Activity Class {. ..} 不存在

android - 异步任务类不适用于较新的 Android 版本

java - 如何将 fragment 设置为 BottomNavigation 的默认 fragment ?

android - 在 Android 中更改布局的背景颜色

java - 将监听器传递给 Android 中的自定义 fragment

Android - 重置不同 Activity 的字段

android - 启动另一个应用程序的 Activity 以获得它的结果

android - Intent 使用图像android eclipse

java - Android 在 2 个 Activity 之间传递 Intent 增量值