简体   繁体   English

类型类是原始类型。 对泛型类型Class的引用 <T> 应该参数化

[英]Type Class is a raw type. References to generic type Class<T> should be parameterized

Class activityItems work fine but i get warning "Type Class is a raw type. References to generic type Class should be parameterized". 类activityItems工作正常,但出现警告“类型类是原始类型。对泛型类型类的引用应参数化”。 How to fix it ? 如何解决?

Here is my code: 这是我的代码:

public class MainActivity extends ListActivity {

    String classes[] = { "AccountActivity", "CountsActivity", "" };
    String listItems[] = { "Accounts", "Counts", "temp" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        View layout = findViewById(R.id.container);
        Drawable background = layout.getBackground();
        background.setAlpha(110);

        setListAdapter(new ArrayAdapter<String>(this, 
                android.R.layout.simple_list_item_1, listItems));

    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String item = classes[position];
        try {
            Class activityItems = Class.forName("com.arbaz.hk." + item);
            Intent intent = new Intent(this, activityItems);
            startActivity(intent);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

I think it may just be a case of changing this: 我认为这可能只是更改此情况的一种情况:

Class activityItems = Class.forName("com.arbaz.hk." + item);

to: 至:

Class<?> activityItems = Class.forName("com.arbaz.hk." + item);

That way you're still not saying you know what the T in Class<T> is, but you're demonstrating that you're at least aware that it is a generic type, so the compiler won't erase all trace of generics from the signatures etc as it would otherwise. 你还没有说这样的话,你知道什么TClass<T>的,但是你证明你至少知道它一个通用型,所以编译器不会删除仿制药的所有痕迹从签名等,否则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告-类是原始类型。 对泛型类型Class的引用 <T> 应该参数化 - Warning - Class is a raw type. References to generic type Class<T> should be parameterized 类是原始类型。 对泛型类型Class的引用 <T> 应该参数化 - Class is a raw type. References to generic type Class<T> should be parameterized 为什么我收到警告:Class是原始类型。对泛型类型<T>的引用应该参数化“? - Why am I getting the warning :Class is a raw type. References to generic type Class<T> should be parameterized"? 如何在Eclipse中禁用警告 - 'Class是原始类型。对泛型类型<T>的引用应该参数化' - How to disable warning in Eclipse - 'Class is a raw type. References to generic type Class<T> should be parameterized' Eclipse警告 - 类是原始类型。 对泛型类的引用 <T> 应该参数化 - Eclipse warning - Class is a raw type. References to generic type Class<T> should be parameterized AddLinkEntry类是原始类型。 对泛型类型AddLinkEntry类的引用 <T> 应该参数化 - AddLinkEntry Class is a raw type. References to generic type AddLinkEntry Class<T> should be parameterized 原始类型。 对泛型类型的引用应该被参数化 - Raw type. References to generic types should be parameterized AdapterView是原始类型。 泛型类型AdapterView的引用 <T> 应该参数化 - AdapterView is a raw type. References to generic type AdapterView<T> should be parameterized 可比是原始类型。 对通用类型Comparable的引用 <T> 应该参数化 - Comparable is a raw type. References to generic type Comparable<T> should be parameterized JComboBox是原始类型。应参数化对泛型类型JComboBox <E>的引用 - JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM