Scala 2.10.0 RC2 和可选参数 [英] Scala 2.10.0 RC2 and optional parameters
问题描述
我正在试验 Scala 宏,它们是 Scala 2.10 的一部分,但是当我尝试编译时(使用 sbt) 我收到以下错误:
I am experimentin with Scala Macros, which are part of Scala 2.10, but as I try to compile (Using sbt) I get the following error:
[error] .../API.scala:9: not enough arguments for constructor OAuth:
(requestMethod: String, consumerSecret: String, consumerKey: String,
signatureMethod: String, version: String)jm.oauth.OAuth
[error] private val oauth = new OAuth(OAuth.POST, oauthConsumerSecret,
oauthConsumerKey, OAuth.HMAC_SHA1)
你可以找到OAuth
类的实现此处.
scala 2.10 和可选参数是否有任何不兼容?
Is there any incompatibility between scala 2.10 and optional parameters?
使用 Scala 2.9.1 编译的完全相同的代码运行良好.
The very same code, compiled with scala 2.9.1, worked perfectly.
推荐答案
如果您创建的文件只包含此类定义:
If you create a file containing only this class definition:
class Optional(x: Int = 0)
然后用 Scala 2.9.2 编译它并在生成的类上运行 javap
,你会看到:
Then compile it with Scala 2.9.2 and run javap
on the resulting class, you'll see this:
public class Optional implements scala.ScalaObject {
public static final int init$default$1();
public Optional(int);
}
用 2.10.0-RC2 和 javap
再次编译它,你会得到这个:
Compile it again with 2.10.0-RC2 and javap
it, and you get this instead:
public class Optional {
public static int $lessinit$greater$default$1();
public Optional(int);
}
所以不,默认参数在 2.10 中完全没问题,您刚刚遇到了一个具体示例,说明主要 Scala 版本之间缺乏二进制兼容性.
So no, default arguments are perfectly fine in 2.10, you've just run into a concrete example of the lack of binary compatibility between major Scala versions.
这篇关于Scala 2.10.0 RC2 和可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!