Talk:Intersection type
| This article is rated Start-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
Java really supporting intersection types?
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)
- I don't think the specific syntax a language uses matters to the concepts it supports. In this case you simply didn't write correct Java.
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 | ^
- This doesn't mean that Java allows you to do everything intersection types allow you to do, but it does – as you said – allow a restricted form of it.
- Kavuldra (talk) 14:07, 22 January 2022 (UTC)
References
- ^ "Java Software". Retrieved 2019-08-08.
- ^ "IntersectionType (Java SE 12 & JDK 12)". Retrieved 2019-08-01.
Content Disclaimer
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.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.