mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 08:45:34 +07:00
Java: Don't show warnings at reflection access to members of the class if a subclass could be passed at that place (IDEA-177983, IDEA-173505)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
class Bugs {
|
||||
static class EnumMethod {
|
||||
public static <T extends Enum<T>> boolean isEnum(final Class<T> enumClass, final String candidate) {
|
||||
try {
|
||||
final Method method = enumClass.getMethod("valueOf", String.class);
|
||||
Object o = method.invoke(null, candidate);
|
||||
System.out.println(o.getClass() + "." + o);
|
||||
return true;
|
||||
}
|
||||
catch (final IllegalArgumentException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class ConstructorInSubclass {
|
||||
static abstract class X {
|
||||
}
|
||||
|
||||
public static class Y extends X {
|
||||
public Y(int i) {
|
||||
System.out.println("ok");
|
||||
}
|
||||
}
|
||||
|
||||
static X test(Class<? extends X> clazz) throws Exception {
|
||||
return clazz.getConstructor(int.class)
|
||||
.newInstance(1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test(Y.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user