Scala 案例类数量限制和 jvm 254 限制

问题描述 投票:0回答:2

新的 Scala 案例类数量限制是多少。

在 scala 2.11 中,案例类的 22 个限制被删除。

新的限制是多少?

是否可以超出jvm限制254

谢谢

java scala
2个回答
2
投票

没有新的限制。更改的目的是删除该限制(请参阅this)。由于它已被删除,因此理论上它在 Scala 方面是无限的。如果您的表有超过 254 个字段,那么我强烈建议您规范化数据库设计,甚至更彻底地重塑您的数据库模式,因为当一个表中有 254 个字段时,显然出现了问题。


0
投票

事实上的限制是254,由于前面提到的JVM限制,这会产生错误“平台限制:参数列表的长度不能超过254”。对于具有 100 多个字段的案例类,您还可能会遇到 StackOverflowError,除非在编译期间提供了足够的堆栈内存。

作为一种解决方法,您可以嵌套案例类,每个案例类都有 < 254 columns (similar to the workaround for the 22 limit). Or, you can use a normal class rather than a case class (just make sure that the class constructor has a parameter list < 254, or you may get the same error). If it's possible to redesign the data model to reduce the number of columns in one table, that's also a good option.

请参阅这个答案,其中有更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.