Fluent pattern matching for Java.
Matcha is an library providing a pattern-matching system for Java. It primarily focuses on being fluent, concise, and extendable.
public class NumberDescriber {
public static String describeNumber(Number number) {
return when(number).matchedTo(String.class)
.is(Double.class).then(i -> i + " is a double.")
.matches(n -> (n.intValue() & 1) != 0).then(i -> i + " is odd.")
.matches(42).then("42 is an interesting number.")
.otherwise(n -> "I don't have much to say about " + n + ".");
}
}
Here are some other interesting projects that also implement pattern matching in Java: