36 lines
694 B
Plaintext
36 lines
694 B
Plaintext
|
import java.lang.Integer;
|
||
|
import java.lang.Double;
|
||
|
import java.lang.String;
|
||
|
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";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|