mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
32 lines
639 B
Java
32 lines
639 B
Java
class TestInstanceOfPattern {
|
|
private String s = "field";
|
|
void test(Object obj) {
|
|
if (obj instanceof String s) {
|
|
if (s.contains("abc")) {}
|
|
} else {
|
|
if (s.contains("def")) {}
|
|
}
|
|
}
|
|
void test2(Object obj) {
|
|
if (!(obj instanceof String s)) {
|
|
if (s.contains("abc")) {}
|
|
} else {
|
|
if (s.contains("def")) {}
|
|
}
|
|
}
|
|
void test3(Object obj) {
|
|
if (obj instanceof String s && s.length() > 5) {
|
|
if (s.contains("abc")) {}
|
|
} else {
|
|
if (s.contains("def")) {}
|
|
}
|
|
}
|
|
void test4(Object obj) {
|
|
if (obj instanceof String s || s.length() > 5) {
|
|
if (s.contains("abc")) {}
|
|
} else {
|
|
if (s.contains("def")) {}
|
|
}
|
|
}
|
|
}
|