Package de.unruh.javapatterns
Class Patterns.Instance<U>
- java.lang.Object
-
- de.unruh.javapatterns.Pattern<U>
-
- de.unruh.javapatterns.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 typeU.This pattern matches if the matched value has type
U(runtime type check) and the subpatternpatternmatches as well.Note: If
Uis a generic type, then only the raw type will be checked. (E.g., IfUis, then it will only be checked that the matched value is aCapture<List<String>>List. However, the subpattern is allowed to have type parameter. This is analogous to how the Java type cast works (e.g.,List<String>()).List<String>)objectFor technical reasons, constructing this pattern has somewhat uncommon invocation syntax:
new Instance<U>(pattern) {}wherepatternis the subpattern.Example:
new Instance<will match anyList<String>>(x) {}Listand assign it to the capturexwhich can be of type.Capture<List<String>>
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedInstance(@NotNull Pattern<? super U> pattern)See the class description for how to create this pattern.
-
-
-
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
-
-