Skip to content

Instantly share code, notes, and snippets.

@RodrigoPinho
Created October 23, 2021 23:17
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/72b71eef4ee1e02ce3ea60a224dc746f to your computer and use it in GitHub Desktop.
Save RodrigoPinho/72b71eef4ee1e02ce3ea60a224dc746f to your computer and use it in GitHub Desktop.
public static String getGuardedPatternMessage(Object object) {
return switch (object) {
case String s && (s.length() > 10)->
"Big string, size: " + s.length();
case String s ->
"Small string, size: " + s.length();
default -> "Unsupported Object: " + object.getClass().getSimpleName();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment