-3

I have a legacy large enum with many comments, and the Java compiler gives a "Code too large" error. Will changing the comment type or deleting the comments solve the issue?

I tried splitting the enum, but it's a legacy code and can't be split.

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • 4
    "So, does changing the comment type or deleting the comments will solve the issue." Isn't this something you can test for yourself? (I wouldn't expect it to though, no.) – Jon Skeet Nov 11 '22 at 09:48
  • 2
    Why should changing a comment affect the code at all? When the large enum causes a “code too large” error, then most likely, the large enum is too large. If this legacy code ever worked, it must have lived on a knife edge, barely being compilable but now failing due to subtle differences in the compiler implementation. How many constants are we talking about? – Holger Nov 11 '22 at 09:59
  • 1
    Does this answer your question? ["Code too large" compilation error in Java](https://stackoverflow.com/questions/2407912/code-too-large-compilation-error-in-java) – Tim Moore Nov 11 '22 at 10:02

1 Answers1

1

This error typically is seen when a method exceeds 65536 bytes (64 KB) in size. Search for the particular method and try some of the following:

  • Split the method into two or more methods
  • Remove any redundancy (such as similar loop executing twice, etc.)
  • Remove any comments (which may be inside the method)

Because the method itself is more 64 KB, the entire file may be too large. I would consider splitting the file into more files using classes.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 3
    What is the relevance of “Remove any comments”? What effect should comments have on the size of the compiled code? – Holger Nov 11 '22 at 10:04