2023-06-27 18:25:31 +00:00
|
|
|
import java.lang.Integer;
|
2023-06-28 20:52:18 +00:00
|
|
|
import java.lang.Double;
|
|
|
|
import java.lang.String;
|
2023-07-17 17:50:58 +00:00
|
|
|
import java.lang.Object;
|
2023-06-27 18:25:31 +00:00
|
|
|
|
|
|
|
public class Instanceof{
|
2023-06-28 20:52:18 +00:00
|
|
|
void checkInstanceof() {
|
2023-06-27 18:25:31 +00:00
|
|
|
var a = 4;
|
|
|
|
return (a instanceof java.lang.Integer);
|
|
|
|
}
|
2023-06-28 20:52:18 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-06-27 18:25:31 +00:00
|
|
|
}
|