JavaPatternMatching/resources/syntaxtreegenerator/javFiles/Instanceof.jav

36 lines
694 B
Plaintext
Raw Normal View History

import java.lang.Integer;
import java.lang.Double;
import java.lang.String;
2023-07-17 17:50:58 +00:00
import java.lang.Object;
public class Instanceof{
void checkInstanceof() {
var a = 4;
return (a instanceof java.lang.Integer);
}
void checkInstanceOfWithPattern(){
var b = 4.0;
if(b instanceof java.lang.Double d){
return d;
}else{
return "Kein Double";
}
}
2023-07-17 17:50:58 +00:00
void checkInstanceOfWithGuardedPattern(){
var obj = "test";
var flag;
if (obj instanceof String s && s.length() > 5) {
flag = s.contains("jdk");
}
}
record Point(int x, int y){ }
boolean equals(Object o) {
return (o instanceof Point other)
&& x == other.x
&& y == other.y;
}
}