gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:31:50 26 4
gpt4 key购买 nike

在 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).



上面这句话的意思很清楚。

但我不清楚为什么我们有 [F1:=T1,...,Fn:=Tn]S 之后

最佳答案

对我来说只是看起来不对。

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

第二:符号错误。 §4.10 引用了子类型和父类(super class)型符号 <: 和 :>,但实际使用的是替换符号 :=(实际上在版本 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 有括号,但这只是意味着对每个类型参数进行边界检查。

关于java - JSL 中的符号 S[F1 :=T1, ...,Fn:=Tn],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33534050/

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