Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what way is Java "almost entirely nominally typed"?

Tags:

java

typing

I read from this article that "Java is almost entirely nominally typed". So there are structurally typed parts in Java.

Which are the nominal and structural parts of the Java type system?

like image 488
ipatina Avatar asked Jan 23 '26 14:01

ipatina


1 Answers

According to an earlier post by the same author - 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.)

So, arrays and parts of generics are structural types.

I think the structural types may be something like <T extends A & B> being a supertype of <T extends A>, or Object[] being a supertype of String[][]. These type compatibilities are not based solely on their name.

like image 131
fgb Avatar answered Jan 26 '26 04:01

fgb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!