Java “constant string too long” compile error. Only happens using Ant, not when using Eclipse

前端 未结 11 2177
抹茶落季
抹茶落季 2020-12-01 15:25

I have a few really long strings in one class for initializing user information. When I compile in Eclipse, I don\'t get any errors or warnings, and the resulting .jar runs

11条回答
  •  没有蜡笔的小新
    2020-12-01 16:12

    Another trick, if I'm determined to put a long string in the source, is to avoid the compiler detecting it as a constant expression.

    String dummyVar = "";
    String longString = dummyVar +
        "This string is long\n" + 
        "really long...\n" + 
        "really, really LONG!!!";
    

    This worked for a while, but if you keep going too far the next problem is a stack overflow in the compiler. This describes the same problem and, if you're still determined, how to increase your stack - the problem seems to be the sheer size of the method now. Again this wasn't a problem in Eclipse.

提交回复
热议问题