Java SE 规范 |S|象征

标签 java specifications subtyping

我正在阅读关于子类型和转换的 Java 规范,我知道 S <: T 意味着 S 是 T 的子类型。但是,我不明白 |S| 是什么意思。 <:|T|方法?例如在这种情况下:

One type argument is a type variable or wildcard, with an upper bound (from capture conversion, if necessary) of S; and the other type argument T is not a type variable or wildcard; and neither |S| <: |T| nor |T| <: |S|.

|T| T 引用的类型是什么?它指的是T的类别吗?

最佳答案

符号“|T|”表示类型“T”的类型删除,根据 JLS, Section 4.6 中类型删除的定义.

Type erasure is a mapping from types (possibly including parameterized types and type variables) to types (that are never parameterized types or type variables). We write |T| for the erasure of type T. The erasure mapping is defined as follows:

  • The erasure of a parameterized type (§4.5) G is |G|.

  • The erasure of a nested type T.C is |T|.C.

  • The erasure of an array type T[] is |T|[].

  • The erasure of a type variable (§4.4) is the erasure of its leftmost bound.

  • The erasure of every other type is the type itself.

所以,“|S| <: |T|”意味着S的删除是T的删除的子类型。

关于Java SE 规范 |S|象征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32381695/

相关文章:

java - 我们可以用 Java(或 Kotlin)表示 "self class"吗?

java - 如何在jsp中的表格顶部显示变量值?

java - 异常java.lang.VerifyError : Bad type on operand stack happend in Heron

"from"和 "to"状态下的 CSS 转换值

xml - 是否有简化的 XML 子集的规范?

scala - 隐式搜索不指导类型推断在 Scala 中查找父类(super class)型

java - 如何在 Java 应用程序中处理多种语言?

java - Hazelcast:SqlPredicate 面临 IllegalArgumentException

JavaScript "\8"文字

java - 接口(interface)和实现类中的泛型参数化函数基本原理