草庐IT

getUnsafe

全部标签

java - 使用 Unsafe.getUnsafe().throwException 抛出异常

我在java.lang.Class#newInstance0中发现了一些有趣的代码://Runconstructortry{returntmpConstructor.newInstance((Object[])null);}catch(InvocationTargetExceptione){Unsafe.getUnsafe().throwException(e.getTargetException());//Notreachedreturnnull;}查看Unsafe.getUnsafe().throwException语句。看起来一个已检查的异常是从一个没有声明要抛出的方法中抛出的!