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 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
,
then it will only be checked that the matched value is a Capture
<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>)object
For technical reasons, constructing this pattern has somewhat uncommon invocation syntax:
new Instance<U>(pattern) {}
where pattern
is the subpattern.
Example: new Instance<
will match any List
<String>>(x) {}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
-
Constructor Details
-
Instance
See the class description for how to create this pattern.- Parameters:
pattern
- the subpattern
-