接口是类吗? [英] Is an interface a class?

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

问题描述

接口是一种特殊的类吗?或者您可以说一个接口根本不是一个类吗?

Is an interface a special kind of class or can you say that an interface isn't a class at all?

推荐答案

接口不是类,但是您可以说接口和类都是类型.

An interface isn't a class, but you could say that both interfaces and classes are types.

来自 Java规范:

在Java编程语言中,每个变量和每个表达式都具有可以在编译时确定的类型.该类型可以是原始类型或引用类型.引用类型包括类类型和接口类型.

In the Java programming language, every variable and every expression has a type that can be determined at compile-time. The type may be a primitive type or a reference type. Reference types include class types and interface types.

尽管有一个名为 可以代表类和接口:

Notice though there is a special class called Class<T> that can represent both classes and interfaces:

Class类的实例表示正在运行的Java应用程序中的类和接口.

Instances of the class Class represent classes and interfaces in a running Java application.

接口由Class实例表示的事实,其中 isInterface true可能会给您一种界面只是一种特殊类型的类的印象.但是事实并非如此.

The fact that an interface is represented by a Class instance where isInterface is true could give you the impression that an interface is just a special type of class. However this is not the case.

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

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