java - 接口(interface)的默认方法存储在内存中的什么位置?

标签 java memory-management java-8 jvm default-method

我看了很多帖子,但似乎都在回答接口(interface)的静态方法存储在哪里。但是,接口(interface)可以有抽象方法、静态方法和默认方法。我知道静态和抽象方法。但是,我无法在内存中找到与默认方法存储相关的任何内容。

我可能是错的,但我认为默认方法将存储在静态堆空间中,就像实例方法与类一起存储一样。但是,除此之外,考虑到实现类不会覆盖接口(interface)中默认方法的实现并且不存在菱形问题,如果默认方法在被调用后也被分配给堆栈帧,我也会感到困惑。

我引用了以下链接:

Where are methods stored in memory?

Where are static methods and static variables stored in Java?

最佳答案

就 JVM 内存中的存储而言,默认方法没有什么特别之处。与其他类方法一样,它们是 method area 的一部分。 .

I am confused if default methods are also allocated to stack frames once they are called considering that the implementing class does not override the implementation of default method in interface and there is no diamond problem.

stack frames在调用方法时分配,同样与方法的种类(静态,默认等)无关。不要将它们在运行时调用 期间的使用与方法代码(和其他类元数据)的存储位置混淆。

关于java - 接口(interface)的默认方法存储在内存中的什么位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67770479/

相关文章:

java - 在我的 java 类中使用 scala.collection.immutable.Map

java - 为什么 Eclipse Java Package Explorer 在某些类上显示问号?

java - 运行内存密集型 Java 应用程序后操作系统变慢的原因是什么?

java - 将大查询结果附加到java appengine中的现有表

memory-management - ELF 头和进程虚拟内存中的不同地址

c# - 为什么非托管代码会将内存增加到特定限制?

c - `realloc` 实际上是如何在后台工作的?

java - Hibernate错误: Invocation of init method failed; nested exception is org. hibernate.boot.archive.spi.ArchiveException:无法构建ClassFile

Java从windows机器远程访问linux机器

java - 使用 ScheduledExecutorService View 不会更新