什么是lub(null,Double)? [英] What is lub(null, Double)?

查看:151
本文介绍了什么是lub(null,Double)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表15.25-B 表示条件表达式的类型

Table 15.25-B in JLS version 8 says that the type of a conditional expression

true ? null : 0.0

lub(null,Double),其中lub似乎是这似乎与Double类型有所不同,或者他们可能只是写了Double,就像在表中的其他地方一样.不过,目前尚不清楚有什么区别.我试图从4.10.4节中解决这个问题,但是到那时我已经了解了

This appears to be distinct from the Double type somehow, or they probably would have just written Double, like they did elsewhere in the table. It's not clear what the difference could be, though. I tried to work it out from section 4.10.4, but by the time I got to the part about

让lub(U1 ... Uk)为:

Let lub(U1 ... Uk) be:

最佳(W1)& ...&最佳(Wr)

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

似乎他们在说这种类型是null和Double类型的交集类型,这没有任何意义.

it seemed like they were saying that this type is an intersection type of the null and Double types, which makes no sense.

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

What is lub(null, Double)? How does a conditional expression with this type behave differently from if its type were just defined as Double?

推荐答案

它只是Double.

非正式地,lub(null, Double)是最恰当的类型,它包含null类型和Double类型的所有值,而最具体的类型是Double.

Informally, lub(null, Double) is (a decent approximation to) the most specific type that contains all values of the null type and the Double type, and the most specific such type is Double.

形式上,我们可以在

Formally, we can work through the definition of lub in JLS section 4.10.4, and we find that lub(null, Double) is Double:

一组引用类型的最小上限或"lub"是 比任何其他共享超类型更具体的共享超类型 (也就是说,其他共享超类型都不是最小上位的子类型 边界).这种类型的lub(U1,...,Uk)如下确定.

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.

如果k = 1,则lub本身就是类型:lub(U)= U.

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

否则:

对于每个Ui(1≤i≤k):

For each Ui (1 ≤ i ≤ k):

让ST(Ui)成为Ui的超类型集.

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

ST(null )是所有引用类型的集合,而ST(Double)是{Object,Number,Double}.

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

让EST(Ui)(Ui的已删除超类型的集合)为:

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

EST(Ui)= {| W | | ST(Ui)中的W}其中| W |是W的擦除.

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

EST(null)是所有参考类型的擦除集,而EST(Double)是{Object,Number,Double}.

EST(null) is the set of the erasures of all reference types, and EST(Double) is {Object, Number, Double}.

让EC(U1 ... Uk的已删除候选集)成为所有EST(Ui)(1≤i≤k)集的交集.

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

EC是EST(空)和EST(双精度)的交集,因此EC是{Object,Number,Double}.

EC is the intersection of EST(null) and EST(Double), so EC is {Object, Number, Double}.

让MEC(U1 ... Uk的最小擦除候选集)为:

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

MEC = {V | EC中的V,对于EC中的所有W≠V,情况并非如此 W< ;: V}

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

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

MEC is the set of all types in EC that have no proper subtype in EC. Double is a proper subtype of both Number and Object, so MEC = {Double}. (W <: V means that the type W is a subtype of the type V. A type is considered a subtype of itself, so they specify W ≠ V to count only proper subtypes.)

对于MEC的任何属于通用类型的元素G:

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

[很多文本]

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

MEC contains no generic types, so we can skip this.

让lub(U1 ... Uk)为:

Let lub(U1 ... Uk) be:

最佳(W1)& ...&最佳(Wr)

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

其中Wi(1≤i≤r)是MEC的元素,最小擦除 U1 ... Uk的候选集;

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):

如果X是通用的,则Best(X)=候选(X);否则为X.

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

Candidate是在我们跳过的部分中定义的;我们仍然可以跳过它,因为它仅对通用类型重要.

Candidate was defined in the part we skipped; we can still skip it, since it only matters for generic types.

lub(null,Double)是Best(Double),而Best(Double)是Double,因此lub(null,Double)是Double.

lub(null, Double) is Best(Double), and Best(Double) is Double, so lub(null, Double) is Double.

这篇关于什么是lub(null,Double)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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