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.
a) Methods should not have more than an average of 30 code lines (not counting line spaces and comments). b) A class should contain an average of less than 30 methods, resulting in up to 900 lines of code. c) A package shouldn't contain more than 30 classes, thus comprising up to 27,000 code lines.
In PMD, the default behavior of the TooManyMethods rule is to identify and flag classes with 10 or more methods as potential errors. This is just an arbitrary number, though.
There are two types of methods in Java: Predefined Method. User-defined Method.
The int type in Java can be used to represent any whole number from -2147483648 to 2147483647.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With