[英]Error: Code too Large in Generated Java File
I'm coding a Java application that reads a .MID file and generates a .java(wich when compiled and executed generates a .wav file), however, the generated .java file cointains a very large constructor method, so the generated code won't compile. 我正在编写一个Java应用程序的代码,该应用程序读取.MID文件并生成一个.java(在编译和执行时会生成一个.wav文件),但是,生成的.java文件包含一个非常大的构造方法,因此生成的代码赢得了不编译。 I'm aware of the maximum size of 64kb for each method, but is there a way to change it? 我知道每种方法的最大大小为64kb,但是有没有办法更改? Thanks! 谢谢!
Simply make your app break down the constructor into several methods - that is, the constructor calls multiple small methods to do its job. 只需使您的应用程序将构造函数分解为几种方法即可,也就是说,构造函数调用多个小方法来完成其工作。 This also makes debugging easier as fixing bugs scattered across methods one method at a time is more of a piece of cake rather than dealing with a huge, broken method. 这也使调试更容易,因为一次解决一个方法中分散的错误更像是小菜一碟,而不是处理一个庞大的破碎方法。
Here's an example of a method (not necessarily a constructor, in fact you can break down all kinds of methods) broken down into smaller methods: 这是一个方法示例(不一定是构造函数,实际上您可以分解所有方法)分解为较小的方法:
public int doLotsOfStuff(String arg0, int arg1, boolean arg2, BiFunction<Boolean, String, Integer> arg3){
arg0 = reverse(arg0);
foo(arg1, arg2);
return bar(arg0, Integer.valueOf(arg1), arg2, arg3);
}
String reverse(String arg0){
StringBuilder foobar = new StringBuilder(arg0);
foobar.reverse();
return foobar.toString();
}
void foo(int arg0, boolean arg1){
System.out.println(arg1 ? ~arg0 : arg0);
}
<A, B> int bar(String arg0, A arg1, B arg2, BiFunction<B, String, A> arg3){
return String.valueOf(arg3.apply(arg2, arg1)).concat(arg0).hashCode();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.