任何人都可以指导我解决这个问题(记住这个问题是在 Java Reflection 上下文中)
There are is a java class named "A" having an inner class named "B".When i compile this java file then it create 2 versions of .class file one named as "A.class" & "A$B.class" and If "A" class have 2 inner classes i.e B,C then there will be 3 version created "A.class" & "A$B.class" & "A$C.class"
Why this is happen.And if i want to read the .class file then what .class file i read b/c when i gave A.class then it will ask for A$B.class and give Caused by: java.lang.ClassNotFoundException: A$B.class
如果我们给出 A$B.class 那么它会给出异常
java.lang.NoClassDefFoundError:
java.lang.ClassNotFoundException
class A {
String _name="Tom";
class B{
int _phoneNo=8384040;
}
}
最佳答案
There are is a java class named "A" having an inner class named "B"
所以你有两个类,并且应该有两个类文件。
If "A" class have 2 inner classes i.e B,C
您有三个类和三个类文件。
And if i want to read the .class file then what .class file i read b/c when i gave A.class then it will ask for A$B.class
当你读取A.class文件时,你只是在读取一个文件。它不会要求您提供任何其他信息。
and give Caused by: java.lang.ClassNotFoundException: A$B.class
只有当此类不在您的类路径中时才会发生这种情况,这是完全不同且不相关的事情。
<小时/>这是加载类的方式,但创建这些类的实例。无需读取底层类,甚至无需知道它们在磁盘上的排列方式。
A a = new A(); // creates an instance of A
A.B b = a.new A.B(); // creates an instance of A.B which is "inside" 'A a'.
关于java - java中的.class文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5459774/