一个Java类可以拥有的最大方法数是多少? [英] What is the maximum number of methods a Java class can have?
本文介绍了一个Java类可以拥有的最大方法数是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想构建一个非常大的Java类,对Java类可以有多少方法有任何限制?它可以进入数百万的方法吗?
更新:
目的是,做一个上帝类。
解决方案
根据 Java类文件规范限制为 65535 :
Java虚拟机
Java虚拟机的以下限制隐含在
class
文件格式中: / p>
- 类或接口可声明的方法数量限制为65535,大小为
methods_count
项目(§4.1)。注意,ClassFile
结构的ClassFile
结构的methods_count
项的值不包括从超类或超级接口继承的方法。
I am thinking to build a VERY large Java class, is there any limit on the number of methods the Java class can have? Can it go into the millions of methods?
update: The purpose is, yes, to make a "God" class.
解决方案
According to the Java class file specification the limit is 65535:
4.10 Limitations of the Java Virtual Machine
The following limitations of the Java virtual machine are implicit in the
class
file format:
- The number of methods that may be declared by a class or interface is limited to 65535 by the size of the
methods_count
item of theClassFile
structure (§4.1). Note that the value of themethods_count
item of theClassFile
structure does not include methods that are inherited from superclasses or superinterfaces.
这篇关于一个Java类可以拥有的最大方法数是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文