gpt4 book ai didi

java - 什么是 lub(null, Double)?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:46:14 25 4
gpt4 key购买 nike

Table 15.25-B在 JLS 版本 8 中说条件表达式的类型

true ? null : 0.0

lub(null,Double),其中 lub 似乎是来自 section 4.10.4 的一些疯狂不可理解的东西.

这似乎与 Double 类型不同,或者他们可能只是写成 Double,就像他们在表的其他地方所做的那样。不过,尚不清楚可能存在什么差异。我试图从第 4.10.4 节开始解决这个问题,但是当我到达关于

的部分时

Let lub(U1 ... Uk) be:

Best(W1) & ... & Best(Wr)

他们好像在说这种类型是 null 和 Double 类型的交集类型,这毫无意义。

什么是lub(null, Double)?具有此类型的条件表达式的行为与其类型仅定义为 Double 有何不同?

最佳答案

就是Double .

非正式地,lub(null, Double)是(一个合适的近似值)包含 null 的所有值的最具体的类型类型和 Double类型,最具体的类型是 Double .

形式上,我们可以通过 lub 的定义来工作在 JLS section 4.10.4 ,我们发现 lub(null, Double)Double :

The least upper bound, or "lub", of a set of reference types is a shared supertype that is more specific than any other shared supertype (that is, no other shared supertype is a subtype of the least upper bound). This type, lub(U1, ..., Uk), is determined as follows.

If k = 1, then the lub is the type itself: lub(U) = U.

Otherwise:

For each Ui (1 ≤ i ≤ k):

Let ST(Ui) be the set of supertypes of Ui.

ST(null) is the set of all reference types , ST(Double) 是 {Object, Number, Double}。

Let EST(Ui), the set of erased supertypes of Ui, be:

EST(Ui) = { |W| | W in ST(Ui) } where |W| is the erasure of W.

EST(null)是所有引用类型的删除集合,EST(Double)是{Object, Number, Double}。

Let EC, the erased candidate set for U1 ... Uk, be the intersection of all the sets EST(Ui) (1 ≤ i ≤ k).

EC 是 EST(null) 和 EST(Double) 的交集,所以 EC 是 {Object, Number, Double}。

Let MEC, the minimal erased candidate set for U1 ... Uk, be:

MEC = { V | V in EC, and for all W ≠ V in EC, it is not the case that W <: V }

MEC 是 EC 中没有适当子类型的所有类型的集合。 Double 是 Number 和 Object 的真子类型,所以 MEC = {Double}。 ( W <: V 表示类型 W 是类型 V 的子类型。类型被认为是其自身的子类型,因此他们指定 W ≠ V 以仅计算适当的子类型。)

For any element G of MEC that is a generic type:

[lots of text]

MEC 不包含泛型类型,因此我们可以跳过这一点。

Let lub(U1 ... Uk) be:

Best(W1) & ... & Best(Wr)

where Wi (1 ≤ i ≤ r) are the elements of MEC, the minimal erased candidate set of U1 ... Uk;

and where, if any of these elements are generic, we use the candidate parameterization (so as to recover type arguments):

Best(X) = Candidate(X) if X is generic; X otherwise.

Candidate在我们跳过的部分中定义;我们仍然可以跳过它,因为它只对泛型类型有影响。

lub(null, Double) 是 Best(Double),Best(Double) 是 Double,所以 lub(null, Double) 是 Double。

关于java - 什么是 lub(null, Double)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43506017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com