Java 中的多重继承。通过扩展命令分配优先级
Multiple Inheritance in Java . Assigning priority via extends order
Oracle Java Tutorials, Multiple Inheritance of State, Implementation, and Type:
One reason why the Java programming language does not permit you to extend more than one class is to avoid the issues of multiple inheritance of state, which is the ability to inherit fields from multiple classes. For example, suppose that you are able to define a new class that extends multiple classes. When you create an object by instantiating that class, that object will inherit fields from all of the class's superclasses. What if methods or constructors from different superclasses instantiate the same field?
这个问题难道不能通过分配优先级到所有类子类扩展来轻松解决吗?
class A extends B,C,D
{
}
让我们假设优先级是按照子类声明中提到的升序分配的。
那么B的优先级
请指教。提前致谢。
是的,粗略地说,这就是 Scala 支持使用多个 Traits
扩展 class 的方式
"priorities"是根据linearization equation决定的,和你说的差不多所以没有歧义。
Oracle Java Tutorials, Multiple Inheritance of State, Implementation, and Type:
One reason why the Java programming language does not permit you to extend more than one class is to avoid the issues of multiple inheritance of state, which is the ability to inherit fields from multiple classes. For example, suppose that you are able to define a new class that extends multiple classes. When you create an object by instantiating that class, that object will inherit fields from all of the class's superclasses. What if methods or constructors from different superclasses instantiate the same field?
这个问题难道不能通过分配优先级到所有类子类扩展来轻松解决吗?
class A extends B,C,D
{
}
让我们假设优先级是按照子类声明中提到的升序分配的。
那么B的优先级 请指教。提前致谢。
是的,粗略地说,这就是 Scala 支持使用多个 Traits
扩展 class 的方式"priorities"是根据linearization equation决定的,和你说的差不多所以没有歧义。