Object obj = new Object();
try {
obj.getClass().getConstructor();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
dosomething();
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我不想像这样检查,因为它抛出异常.
还有另外一种方法吗?