Arrays.asList(); 括号里面为什么不能得到int类型的具体元素,看了视频还是不懂。
int[] a1=new int[3];
int[] a2=new int[4];
int[][] a3=new int[2][3];
String[] a4=new String[3];
System.out.println(a1.getClass()==a2.getClass());
System.out.println(a1.getClass()==a3.getClass()); //张孝祥老师视频上运行这句是false,我怎么编译就错了,没得运行。
随便问一下昨天没解决的问题
- 01.import java.lang.reflect.*;
- 02.public class Test {
- 03. public static void main(String[] args) throws Exception
- 04. {
- 05. ReflectPoint pt=new ReflectPoint(3,5);
- 06. Field fieldy=pt.getClass().getField("y"); //pt.getClass().getField("y");
- 07. //java.lang.reflect.Field fieldy=pt.getClass().getField("y");
- 08. System.out.println(fieldy.get(pt));
- 09. Field fieldx=pt.getClass().getField("x");
- 10. System.out.println(fieldx.get(pt));
- 11. }
- 12.}
- 13.
- 14.
- 15.public class ReflectPoint {
- 16. private int x;
- 17. public int y;
- 18. public ReflectPoint(int x, int y) {
- 19. super();
- 20. this.x = x;
- 21. this.y = y;
- 22. }
- 23.}
复制代码
结果为:
5
Exception in thread "main" java.lang.NoSuchFieldException: x
at java.lang.Class.getField(Class.java:1520)
at fanshe1.Test.main(Test.java:11) |
|