Class Patterns.Instance<U>

  • Type Parameters:
    U - the type that the matched value should have
    Enclosing class:
    Patterns

    public abstract static class Patterns.Instance<U>
    extends Pattern<U>
    Pattern that matches if the matched value has a specific type U.

    This pattern matches if the matched value has type U (runtime type check) and the subpattern pattern matches as well.

    Note: If U is a generic type, then only the raw type will be checked. (E.g., If U is Capture<List<String>>, then it will only be checked that the matched value is a List. However, the subpattern is allowed to have type parameter List<String>. This is analogous to how the Java type cast works (e.g., (List<String>)object)).

    For technical reasons, constructing this pattern has somewhat uncommon invocation syntax: new Instance<U>(pattern) {} where pattern is the subpattern.

    Example: new Instance<List<String>>(x) {} will match any List and assign it to the capture x which can be of type Capture<List<String>>.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Instance​(@NotNull Pattern<? super U> pattern)
      See the class description for how to create this pattern.
    • Method Summary

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Instance

        @Contract(pure=true)
        protected Instance​(@NotNull
                           @NotNull Pattern<? super U> pattern)
        See the class description for how to create this pattern.
        Parameters:
        pattern - the subpattern