为什么 Scala 函数限制为 22 个参数? [英] Why are scala functions limited to 22 parameters?

查看:44
本文介绍了为什么 Scala 函数限制为 22 个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

并不是说我实际上已经接近这个极限,但我一直想知道:为什么它们会停留在 Function22/Tuple22.JVM限制?任意选择?

Not that I've actually come close to that limit, but Ive always wondered: Why do they stop at Function22/Tuple22. JVM restriction? Arbitrary choice?

推荐答案

函数和元组被编译器重写为对象,并且只有 Function0Function22Tuple0Tuple22 被定义.我认为 22 的限制完全是任意的,但有限制的原因不是.

Functions and tuples are rewritten as objects by the compiler, and only Function0 through Function22 and Tuple0 through Tuple22 are defined. I think the limit of 22 is entirely arbitrary, but the reason for having a limit is not.

这样想:要运行 Scala 应用程序,运行它所需的类必须存在.如果编译器会为函数动态创建类,那么这些类将不会包含在 Scala 库 JAR 中,因此您必须将它们包含在您的应用程序中.这可以工作,但是您会遇到类的完全限定名称应该是什么的问题:如果它们对于所有应用程序都是相同的,那么您就会发生冲突,因为库将包含相同的类,并且如果名称不是同样,您最终会遇到不兼容问题 -- 库中的函数与应用中的函数不同.

Think of it this way: to run a Scala application the classes needed to run it must be present. If the compiler would dynamically create classes for functions then those classes would not be included in the Scala library JAR, so you would have to include them in your application. That could work, but then you would have the problem of what the classes' fully qualified names should be: if they were the same for all apps then you would have clashes since libraries would contain the same classes, and if the names were not the same you would end up with incompatibilities -- functions from libraries wouldn't be the same as functions in your app.

这篇关于为什么 Scala 函数限制为 22 个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆