是什么在类名的末尾括号角度的符号是什么意思? [英] What do the angle bracketed symbols at the end of a class name mean?

查看:184
本文介绍了是什么在类名的末尾括号角度的符号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如看看这个:

ArrayList<String> arrayList = new ArrayList<String>();

我能使用的&lt;> s的自定义类?我该如何使用他们?

Could I use the <>s with a custom class? How do I use them?

推荐答案

您可以把任何类中的&LT;&GT; 只要它满足了通用类的限制

You can put any class in the <> as long as it fulfills the generic class's constraints:

ArrayList<MyClass> arrayList = new ArrayList<MyClass>();

您可以定义自己的类来使用&LT;&GT; 简单:

You can define your own class to use the <> simply:

class MyGenericClass<E> {
    E e;
    MyGenericClass(E e) { this.e = e; }

    E getE() { return e; }
    void setE(E e) { this.e = e; }
}

现在,你可以使自己的:

Now you can make your own:

MyGenericClass<String> stuff = new MyGenericClass<String>("Foo");
System.out.println(stuff.getE());

这篇关于是什么在类名的末尾括号角度的符号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆