JSL 中的符号 S[F1:=T1,...,Fn:=Tn]

Notation S[F1:=T1,...,Fn:=Tn] in JSL

在 JLS(参数化类型)的第 4.5 节中提到了以下符号: S[F1:=T1,...,Fn:=Tn].

我不太明白这个符号的意思。

在以下段落中提到:

A generic type has type parameters F1,...,Fn with corresponding bounds B1,...,Bn. Each type argument Ti of a parameterized type ranges over all types that are subtypes of all types listed in the corresponding bound. That is, for each bound type S in Bi, Ti is a subtype of S[F1:=T1,...,Fn:=Tn] (§4.10).

上面这句话的意思已经很清楚了

但我不清楚为什么我们在 S

之后有 [F1:=T1,...,Fn:=Tn]

这是我的想法。

符号 [F1:=T1,...,Fn:=Tn] 是每个类型参数 Fi 与具体类型(或通配符)Ti, i=1,2,...n.

的替换

泛型 class 可以被认为是一个带有 (n+1) 个参数 f(F1,F2,...,Fn, S) 的函数,其中 Fi - 是一个类型参数,而 S 属于以下有限集 {B1,B2,...,Bn}。 如果我们用 [F1:=T1,...,Fn:=Tn] 代替,我们得到一个带有一个参数的函数: g(s)=f(T1,T2,...,Tn,S).

考虑到 [F1:=T1,...,Fn:=Tn]FiTi, i=1,2,...,n 的替代 我们可以引入新的符号: f(T1,T2,...,Tn,S)=h(S)[F1=T1,...,Fn=Tn].

函数 h(S) 应该是线性的:h(S)=S

最后我们有: f(T1,T2,...,Tn,S)=S[F1=T1,...,Fn=Tn].

因此概念 S[F1=T1,...,Fn=Tn] 表示:获取固定值 Fi=Ti.

的上限 Bi 之一

我觉得不对劲。

第一:去掉括号部分,这句话是对前面陈述的正确重述,都符合我对java语言的理解。

其二:写法错误。 §4.10 引用了子类型和超类型符号 <: 和 :>,但实际使用的是替换符号 := (实际上在版本 8 中未定义为替换符号,但在版本 7 中,并在本节的其他部分中用作替换文件).

最后:以前版本的 JSL 有一个更荒谬的相同符号版本。

4.5. Parameterized Types

A generic class or interface declaration C (§8.1.2, §9.1.2) with one or more type parameters A1,...,An which have corresponding bounds B1,...,Bn defines a set of parameterized types, one for each possible invocation of the type parameter section.

Each parameterized type in the set is of the form C where each type argument Ti ranges over all types that are subtypes of all types listed in the corresponding bound. That is, for each bound type Si in Bi, Ti is a subtype of Si[F1:=T1,...,Fn:=Tn].

同样是括号,但是这次在括号中使用之前甚至没有提到F是什么

当本节在版本 6 和版本 7 之间重写时,似乎括号被错误地复制了。版本 6 有括号,但这只是意味着对每个类型参数进行了边界检查。