JVM在接口和纯抽象类之间的实现区别? [英] JVM Implementation difference between interface and pure abstract class?

查看:142
本文介绍了JVM在接口和纯抽象类之间的实现区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的朋友们想知道JVM内部接口和纯抽象类之间是否确实存在差异,还是仅仅是语法上的糖.

Me and my friends wondered if there really is a difference inside the JVM between interfaces and pure abstract classes, or if it is just really syntactic sugar.

我真的不明白为什么会有区别,但是可能没有那么牵强.

I don't really see why there would be difference, but it might not be so far-fetched.

推荐答案

就字节码(.class文件)而言,它们是完全不同的:

As far as bytecode (.class file) is concerned, they are completely different:

来自 4.1类文件结构:

ClassFile {
    //...
    u2 constant_pool_count;
    cp_info constant_pool[constant_pool_count-1];
    //...
    u2 super_class;
    u2 interfaces_count;
    u2 interfaces[interfaces_count];
}

显然,类可以具有单个超类(是否为abstract)和多个已实现的接口.这是JVM的限制,而不是Java(语言)的限制.

Clearly class can have a single superclass (abstract or not) and multiple implemented interfaces. It is a limitation of JVM, not a Java (the language) restriction.

这篇关于JVM在接口和纯抽象类之间的实现区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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