简体   繁体   English

Java 和 JVM 混淆(如果 Java 可以处理大字符串,为什么不能使用 groovy?)

[英]Java and JVM confusion (if Java can handle a large string why can't groovy?)

I recently ran into an issue with Groovy where I was attempting to deal with a very large string (100k characters).我最近遇到了 Groovy 问题,我试图处理一个非常大的字符串(100k 个字符)。 I got an error that said the string could not be more than 65,535 characters.我收到一个错误,提示字符串不能超过 65,535 个字符。 I did some searches to try to find out more info and ran across this link that said the problem was with the JVM - https://issues.apache.org/jira/browse/GROOVY-2382 .我进行了一些搜索以试图找出更多信息,并浏览了此链接,该链接说问题出在 JVM 上 - https://issues.apache.org/jira/browse/GROOVY-2382

I thought Java ran on the JVM as well and in Java I have had much larger strings.我认为 Java 也可以在 JVM 上运行,而在 Java 中我有更大的字符串。 Just trying to understand.只是试图理解。 Can anyone shed some light on this for me.任何人都可以为我阐明这一点。 Thank you in advance.先感谢您。

Sean肖恩

Looking at the source for java.lang.String the limit is that of Integer.MAX_VALUE which is pretty big.查看 java.lang.String 的来源,限制是 Integer.MAX_VALUE 的限制,它非常大。

So yes there is a limit but 100K is no where near it.所以是的,有一个限制,但 100K 离它很近。

The limit that the Groovy bug refers to it that of a string literal, this isn't the same as creating a very big string. Groovy 错误所指的限制是字符串文字的限制,这与创建一个非常大的字符串不同。

This is a limitation on string literals, ie Strings in the source code.这是对字符串文字的限制,即源代码中的字符串。

It is not a problem for Strings read from a File or some other InputStream.从文件或其他一些输入流中读取的字符串不是问题。

You should move your huge String into a separate text file.您应该将巨大的字符串移动到一个单独的文本文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM