使用 Scala 符号文字会导致 NoSuchMethod
我最近开始使用 Scala。我在其中编写了一个 DSL,可用于描述 medici 中的处理管道。在我的 DSL 中,我使用符号来表示锚点,它可用于在管道中放置叉子(或 T 恤,如果您愿意)。这是一个正确运行的小示例程序:
object Test extends PipelineBuilder {
connector("TCP") / Map("tcpProtocol" -> new DirectProtocol())
"tcp://localhost:4858" --> "ByteToStringProcessor" --> Symbol("hello")
"stdio://in?promptMessage=enter name:%20" --> Symbol("hello")
Symbol("hello") --> "SayHello" / Map("prefix" -> "\n\t") --> "stdio://out"
}
出于某种原因,当我在程序中使用符号文字时,我在运行时收到 NoSuchMethod 异常:
java.lang.NoSuchMethodError: scala.Symbol.intern()Lscala/Symbol;
at gov.pnnl.mif.scaladsl.Test$.<init>(Test.scala:7)
at gov.pnnl.mif.scaladsl.Test$.<clinit>(Test.scala)
at gov.pnnl.mif.scaladsl.Test.main(Test.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.ObjectRunner$$anonfun$run$1.apply(ObjectRunner.scala:75)
at scala.tools.nsc.ObjectRunner$.withContextClassLoader(ObjectRunner.scala:49)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:74)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:154)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
无论如何使用符号,都会发生这种情况。具体来说,我尝试在管道和简单的 println('foo) 语句中使用该符号。
问题:什么可能导致符号文字的存在导致 NoSuchMethodError?在我的 DSL 中,我使用一个隐式函数,它将符号转换为 Anchor 类的实例,如下所示:
implicit def makeAnchor(a: Symbol):Anchor = anchor(a)
遗憾的是,我对 Scala 的理解还很薄弱,我无法想象为什么这可能会导致我的 NoSuchMethodError。
I have recently begun using Scala. I've written a DSL in it which can be used to describe a processing pipeline in medici. In my DSL, I've made use of symbols to signify an anchor, which can be used to put a fork (or a tee, if you prefer) in the pipeline. Here's a small sample program that runs correctly:
object Test extends PipelineBuilder {
connector("TCP") / Map("tcpProtocol" -> new DirectProtocol())
"tcp://localhost:4858" --> "ByteToStringProcessor" --> Symbol("hello")
"stdio://in?promptMessage=enter name:%20" --> Symbol("hello")
Symbol("hello") --> "SayHello" / Map("prefix" -> "\n\t") --> "stdio://out"
}
For some reason, when I use a symbol literal in my program, I get a NoSuchMethod exception at runtime:
java.lang.NoSuchMethodError: scala.Symbol.intern()Lscala/Symbol;
at gov.pnnl.mif.scaladsl.Test$.<init>(Test.scala:7)
at gov.pnnl.mif.scaladsl.Test$.<clinit>(Test.scala)
at gov.pnnl.mif.scaladsl.Test.main(Test.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.ObjectRunner$anonfun$run$1.apply(ObjectRunner.scala:75)
at scala.tools.nsc.ObjectRunner$.withContextClassLoader(ObjectRunner.scala:49)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:74)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:154)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
This happens regardless of how the symbol is used. Specifically, I've tried using the symbol in the pipeline, and in a simple println('foo)
statement.
The question: What could possibly cause a symbol literal's mere existence to cause a NoSuchMethodError? In my DSL I am using an implicit function which converts symbols to instances of the Anchor class, like so:
implicit def makeAnchor(a: Symbol):Anchor = anchor(a)
Sadly, my understanding of Scala is weak enough that I can't think of why that might be causing my NoSuchMethodError.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最可能的解释是,您使用的 Scala 版本与运行时类路径上的版本不同。
检查 Scala 的运行时版本
将以下内容添加到 main() 方法中:
这将告诉您从何处加载 Scala 库,例如:
检查Scala的编译时版本
我不知道你是如何调用scalac的。假设它是从命令行运行的,请运行 scalac -version 。
The most likely explanation is that you are compiling with a different version of Scala than you have on the classpath at runtime.
Checking the run-time version of Scala
Add the following to your main() method:
This will tell you where you are loading the Scala library from, for example:
Checking the compile-time version of Scala
I don't know how you are invoking scalac. Assuming it's from the command line, run
scalac -version
.您是否可能安装了多个版本的 Scala,至少从 2.7.1 源开始( http://scala-tools.org/scaladocs/scala-library/2.7.1/Symbol.scala.html)它看起来像Symbol没有实习生方法?
Could you possibly have multiple versions of Scala installed, as from the 2.7.1 source at least (http://scala-tools.org/scaladocs/scala-library/2.7.1/Symbol.scala.html) it doesn't look like Symbol has an intern method?