gpt4 book ai didi

scala - scala中空类的大小是多少?

转载 作者:行者123 更新时间:2023-12-01 13:32:28 26 4
gpt4 key购买 nike

Scala 中空类的大小是多少?
我使用 SizeEstimator 来获取空类的大小。但是我得到的大小是 1368(字节),看起来比我预期的要大得多。

最佳答案

你是指没有成员的类的 .class 文件的大小?

package mypackage

class EmptyClass {

}

对我来说,在使用 Java 1.8.0_121 的 Windows 上,使用 Scala 2.11,它是 527 字节(文件大小将根据包名称而变化,因为文件包含类和包名称)。

javap 工具显示文件中包含的数据:

$ javap -c -v -cp my-app/target/scala-2.11/classes mypackage.EmptyClass
Classfile /.../mypackage/EmptyClass.class
Last modified 17-Jul-2017; size 527 bytes
MD5 checksum d97a3d664755c085417b469bb84f982b
Compiled from "EmptyClass.scala"
public class mypackage.EmptyClass
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8 mypackage/EmptyClass
#2 = Class #1 // mypackage/EmptyClass
#3 = Utf8 java/lang/Object
#4 = Class #3 // java/lang/Object
#5 = Utf8 EmptyClass.scala
#6 = Utf8 Lscala/reflect/ScalaSignature;
#7 = Utf8 bytes
#8 = Utf8 E1A!
\tQQ)9uscm]:
\r\t\"\=qC\mZ3MA\t)i)1oY1mC&1:L(+4\t
5\rqJg.?)yC\t
= Utf8 <init>
#10 = Utf8 ()V
#11 = NameAndType #9:#10 // "<init>":()V
#12 = Methodref #4.#11 // java/lang/Object."<init>":()V
#13 = Utf8 this
#14 = Utf8 Lmypackage/EmptyClass;
#15 = Utf8 Code
#16 = Utf8 LocalVariableTable
#17 = Utf8 LineNumberTable
#18 = Utf8 SourceFile
#19 = Utf8 RuntimeVisibleAnnotations
#20 = Utf8 ScalaInlineInfo
#21 = Utf8 ScalaSig
{
public mypackage.EmptyClass();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: return
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lmypackage/EmptyClass;
LineNumberTable:
line 5: 0
}
SourceFile: "EmptyClass.scala"
RuntimeVisibleAnnotations:
0: #6(#7=s#8)
Error: unknown attribute
ScalaInlineInfo: length = 0x9
01 00 00 01 00 09 00 0A 00
Error: unknown attribute
ScalaSig: length = 0x3
05 00 00

关于scala - scala中空类的大小是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45145906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com