在java中,继承的成员(静态或实例,方法或字段)会被编译到子类的.class文件中吗?
或者只保留父类(super class)相关成员的链接?
最佳答案
就类文件而言,继承的成员不会复制到子类中。这是 relevant documentation from Oracle (强调):
fields[]
Each value in the fields table must be afield_info
(§4.5) structure giving a complete description of a field in this class or interface. The fields table includes only those fields that are declared by this class or interface. It does not include items representing fields that are inherited from superclasses or superinterfaces.
methods[]
Each value in the methods table must be a method_info (§4.6) structure giving a complete description of a method in this class or interface. [...] Themethod_info
structures represent all methods declared by this class or interface type, including instance methods, class methods, instance initialization methods (§2.9), and any class or interface initialization method (§2.9). The methods table does not include items representing methods that are inherited from superclasses or superinterfaces.
关于java - 成员会被编译成子类的.class 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49503870/