Skip to content

Instantly share code, notes, and snippets.

@RodrigoPinho
Created October 23, 2021 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RodrigoPinho/d9f636437d55440dd1f4f71691f6f2eb to your computer and use it in GitHub Desktop.
Save RodrigoPinho/d9f636437d55440dd1f4f71691f6f2eb to your computer and use it in GitHub Desktop.
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