Java接口扩展了一个抽象类? [英] Java interface extending an abstract class?

查看:385
本文介绍了Java接口扩展了一个抽象类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布的代码片段在接口扩展和抽象类时不会出现任何语法错误。接口 audio 在方法 sort()音乐 c>

I am posting a code snippet that does not give any syntax error when an interface extends and abstract class. The interface audio extends abstract class music in the method sort()

import java.util.List;
abstract class music {}
public interface audio {}

abstract class play implements Comparable <play> {

    public <audio extends music> void sort (List <music> list){
        //do something 
    }

}

我假设接口不能扩展抽象类。任何人都可以解释为什么会这样吗?

I am assuming an interface CAN NOT extend an abstract class. Can any one explain why it is so?

推荐答案

在您的示例中,第二个audio不是接口,而是泛型方法的类型参数。您也可以将其命名为 T

In your example, the second "audio" is not the interface, but a type parameter to your generic method. You could just as well name it T.

这篇关于Java接口扩展了一个抽象类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆