Created
October 23, 2021 23:19
-
-
Save RodrigoPinho/d9f636437d55440dd1f4f71691f6f2eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.rodrigopinho.java17.patternmatching; | |
sealed interface Vehicle permits Car, Bus, Motorcycle { | |
static String sealedVehicle(Vehicle v) { | |
return switch (v) { | |
case Bus b -> "Vehicle type: Bus"; | |
case Car c -> "Vehicle type: Car"; | |
case Motorcycle m -> "Vehicle type: Motorcycle"; | |
}; | |
} | |
} | |
final class Bus implements Vehicle {} | |
final class Car implements Vehicle {} | |
final class Motorcycle implements Vehicle {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment