关于异常(包含部分暴力反射)

Demo:

public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Test test = new Test(4,5);
Field field1 = test.getClass().getDeclaredField("x");
field1.setAccessible(true);
System.out.println(field1.get(test)); }

class Test {
private int x;
public int y;
public Test(int x, int y) {
super();
this.x = x;
this.y = y;
}

以上为暴力反射的一个例子。下面是需要抛出的异常(有提示)
  • NoSuchFieldException
  • IllegalAccessException

重写的clone()需要抛出 CloneNotSupportedException

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容