Operators keyword
is
Type test — equivalent to Java instanceof.
expr is Type checks whether a reference is an instance of the given type. Often paired with guard for early exits or with if for branching.
Affogato
example.aff
func check(obj: Object) {
if obj is String {
println(obj as String)
}
} Generated Java
Example.java
public void check(Object obj) {
if (obj instanceof String) {
System.out.println(((String) obj));
}
} Related
as— Cast expression — equivalent to Java (Type) expr.guard— Swift-style early exit when a condition is false.