mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-30 16:21:49 +07:00
GitOrigin-RevId: 0d5e06632a349494f05b79dab40d37988fdd7412
50 lines
832 B
Java
50 lines
832 B
Java
package com.example;
|
|
|
|
class Foo {
|
|
|
|
public static void main(String[] args) {
|
|
new Foo(Mode.A).run();
|
|
new Foo(Mode.B).run();
|
|
}
|
|
|
|
public interface Supplier<T> {
|
|
T get();
|
|
}
|
|
private final Supplier<MyInterface> supplier;
|
|
|
|
public Foo(Mode mode) {
|
|
supplier = switch (mode) {
|
|
case A -> A::new;
|
|
case B -> B::new; // incorrect warning happening here
|
|
};
|
|
}
|
|
|
|
public void run() {
|
|
supplier.get().doSomething();
|
|
}
|
|
|
|
public enum Mode {
|
|
A,
|
|
B
|
|
}
|
|
|
|
private interface MyInterface {
|
|
void doSomething();
|
|
}
|
|
|
|
private static class A implements MyInterface {
|
|
|
|
@Override
|
|
public void doSomething() {
|
|
System.out.println("A");
|
|
}
|
|
}
|
|
|
|
private static class B implements MyInterface {
|
|
|
|
@Override
|
|
public void doSomething() {
|
|
System.out.println("B");
|
|
}
|
|
}
|
|
} |