原始类型、无界通配符和在泛型中使用 Object 之间有什么区别 [英] What's the difference between raw types, unbounded wild cards and using Object in generics

查看:50
本文介绍了原始类型、无界通配符和在泛型中使用 Object 之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读关于 Effective Java 中泛型的章节.

I am reading the chapter on Generics in Effective Java.

帮助我理解SetSetSet?

以下段落摘自书中.

快速回顾一下,Set 是一个参数化类型,表示set 可以包含任何类型的对象,Set 是通配符类型表示只能包含某些未知对象的集合类型,而 Set 是原始类型,它选择退出泛型类型系统.

As a quick review, Set<Object> is a parameterized type representing a set that can contain objects of any type, Set<?> is a wildcard type representing a set that can contain only objects of some unknown type, and Set is a raw type, which opts out of the generic type system.

某种未知类型"是什么意思?都是Object 类型的未知类型吗?在那种情况下,SetSet 之间的具体区别是什么?

What is meant by "some unknown type"? Are all unknown types of type Object? In that case what is the specific difference between Set<?> and Set<Object>?

推荐答案