gpt4 book ai didi

java - Java "almost entirely nominally typed"以什么方式表示?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:04 26 4
gpt4 key购买 nike

我读自this article “Java 几乎完全是名义上的类型”。所以在 Java 中有结构类型的部分。

Java 类型系统的名义部分和结构部分是什么?

最佳答案

根据同一作者之前的帖子 - removal of function types :

  1. There are two basic approaches to typing: nominal and structural. The identity of a nominal is based on its name; the identity of a structural type is based on what it is composed of (such as "tuple of int, int" or "function from int to float".)

Most languages pick mostly nominal or mostly structural; there are not a lot of languages that successfully mix nominal and structural typing except "around the edges." Java is almost entirely nominal (with a few exceptions: arrays are a structural type, but at the bottom there is always a nominal element type; generics have a mix of nominal and structural too, and this is in fact part of the source of many of people's complaints about generics.)

因此,数组和部分泛型是结构类型。

我认为结构类型可能类似于 <T extends A & B>作为 <T extends A> 的父类(super class)型, 或 Object[]作为 String[][] 的父类(super class)型.这些类型兼容性不仅仅基于它们的名称。

关于java - Java "almost entirely nominally typed"以什么方式表示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44484287/

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