Draft:Covariant Nothing Object
Submission declined on 26 November 2024 by KylieTastic (talk).
Where to get help
How to improve a draft
You can also browse Wikipedia:Featured articles and Wikipedia:Good articles to find examples of Wikipedia's best writing on topics similar to your proposed article. Improving your odds of a speedy review To improve your odds of a faster review, tag your draft with relevant WikiProject tags using the button below. This will let reviewers know a new draft has been submitted in their area of interest. For instance, if you wrote about a female astronomer, you would want to add the Biography, Astronomy, and Women scientists tags. Editor resources
|
Covariant Nothing Object is a pattern used in programming languages like Kotlin or Scala. It allows turning immutable generic classes into singleton objects thanks to usage of covariant type modifier and a bottom type (Nothing
type in Kotlin).
The most notable example is an empty list in Kotlin. List
interface in Kotlin represents a read-only type, and whose type parameter has covariant type modifier, so functions like emptyList()
or listOf()
, that are the standard way to create an instance of an empty list, always return exactly the same object, that is implemented as a subtype of List<Nothing>
. Since Nothing
is a bottom type (a subtype of all types), List<Nothing>
is a subtype of all lists.
This pattern was first described by Marcin Moskała in the Advanced Kotlin book[1].
References
[edit]- ^ Moskała, Marcin (2023). Advanced Kotlin (1 ed.). Poland: Kt. Academy. pp. 20–27. ISBN 978-8396684745.
{{cite book}}
: CS1 maint: date and year (link)
- in-depth (not just passing mentions about the subject)
- reliable
- secondary
- independent of the subject
Make sure you add references that meet these criteria before resubmitting. Learn about mistakes to avoid when addressing this issue. If no additional references exist, the subject is not suitable for Wikipedia.