Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed redundant member variables from 03_Sealed Classes.md #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/03_special_classes/03_Sealed Classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
```run-kotlin
sealed class Mammal(val name: String) // 1

class Cat(val catName: String) : Mammal(catName) // 2
class Human(val humanName: String, val job: String) : Mammal(humanName)
class Cat(catName: String) : Mammal(catName) // 2
class Human(humanName: String, val job: String) : Mammal(humanName)

fun greetMammal(mammal: Mammal): String {
when (mammal) { // 3
Expand All @@ -21,7 +21,7 @@ fun main() {
```

1. Defines a sealed class.
2. Defines subclasses. Note that all subclasses must be in the same package.
2. Defines subclasses. Note that all subclasses must be in the same package. catName, humanName are arguments and do not exist as member variables.
3. Uses an instance of the sealed class as an argument in a `when` expression.
4. A smartcast is performed, casting `Mammal` to `Human`.
5. A smartcast is performed, casting `Mammal` to `Cat`.
Expand Down