Allan Caine
1 min readApr 25, 2018

--

Thank you for your compliment. I appreciate your feedback.

You are very right. For example, here is another interesting point related to Nothing being the subclass of all classes. This sealed class will not compile

sealed class LinkedList<T>  {

data class Node<T>(val payload: T, var next: LinkedList<T> = EmptyList) : LinkedList<T>()

object EmptyList : LinkedList<Nothing>()

}

The out variance modifier is missing. The compiler complains that the default value of next cannot be set. We cannot write

var next: LinkedList<T> = EmptyList

unless we write

sealed class LinkedList<out T>

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Allan Caine
Allan Caine

Written by Allan Caine

Senior Android Developer, TD Bank (Canada) (Opinions are my own)

No responses yet

Write a response