Skip to content

Instantly share code, notes, and snippets.

@tacsio
Created March 25, 2023 11:51
Show Gist options
  • Save tacsio/644996f7b4368eb88a6b23f5743c1c61 to your computer and use it in GitHub Desktop.
Save tacsio/644996f7b4368eb88a6b23f5743c1c61 to your computer and use it in GitHub Desktop.
sealed class Shape permits Circle, Rectangle {
double getArea() {
return switch(this) {
case Circle(double r) -> Math.PI * r * r;
case Rectangle(double h, double w) -> h * w;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment