简体   繁体   English

空抽象类的用途是什么?

[英]What is the use of an empty abstract class?

I want to know that is there any use of empty abstract class in Java? 我想知道Java中有没有使用空抽象类? If so, what is it? 如果是这样,它是什么?

An empty abstract class is very much equivalent to an interface except that it can extend a class abstract classinterface非常相似,只不过它可以扩展一个class

abstract class myAbstractClass // extends anotherClass implements anInterface
{

}

interface myInterface // extends anotherInterface
{

}

This pattern is called Marker interface and SO has a lot of good data about it already: What is the purpose of a marker interface? 这种模式称为Marker接口 ,SO已经有很多关于它的好数据: 标记接口的目的是什么?

you can only inherit from one abstract class. 你只能从一个抽象类继承。 Then this is useful to avoid inheritance. 那么这对于避免继承很有用。

是的,有时你需要一个实现多态的基类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM