Well, I think Java only supports intersection types to some extent. A language implementing true intersection types enables to insert intersection expressions i
| This article is rated Start-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
Language Actively developed Paradigm(s) Status Features Java Yes[1] Supported[2]
- Type refinement
- Interface composition
- Subtyping in width
Well, I think Java only supports intersection types to some extent. A language implementing true intersection types enables to insert intersection expressions into type positions. This isn't the case for Java, see this example (JSHELL JDK 15):
jshell> interface i1{}
| created interface i1
jshell> interface i2{}
| created interface i2
jshell> i1 & i2 = null
| Error:
| cannot find symbol
| symbol: variable i1
| i1 & i2 = null
| Error:
| cannot find symbol
| symbol: variable i1
| i1 & i2 = null
| ^^
| Error:
| cannot find symbol
| symbol: variable i2
| i1 & i2 = null
| ^^
Iconsize (talk) 12:53, 19 March 2021 (UTC)
jshell> interface i1 {}
| created interface i1
jshell> interface i2 {}
| created interface i2
jshell> interface i3 extends i1, i2 {}
| created interface i3
jshell> i3 x = null
x ==> null
jshell> i1 a = x
a ==> null
jshell> i2 b = x
b ==> null
jshell> a = b
| Error:
| incompatible types: i2 cannot be converted to i1
| a = b
| ^
References
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.