gpt4 book ai didi

scala - 当 x.toString 失败时,ScalaRunTime.stringOf(x) 如何不失败?

转载 作者:行者123 更新时间:2023-12-04 23:50:26 25 4
gpt4 key购买 nike

虽然试图找出一些 joda-time DateTime (时间戳格式)问题我打开了一个 REPL

scala -cp joda-time-2.3.jar

忘记添加 joda-convert jar,并最终得到一个
java.lang.AssertionError: assertion failed: org.joda.convert.ToString

( The entire stacktrace )

我能够将其简化为:
> scala -cp joda-time-2.3.jar
Welcome to Scala version 2.11.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val dt = new org.joda.time.DateTime
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
dt: org.joda.time.DateTime = 2014-05-14T17:54:24.511+01:00

scala> scala.runtime.ScalaRunTime.stringOf(dt)
res0: String = 2014-05-14T17:54:24.511+01:00

scala> dt.toString
java.lang.AssertionError: assertion failed: org.joda.convert.ToString

怎么样 ScalaRunTime.stringOf(dt)成功在哪里 dt.toString失败?

最佳答案

您没有发布堆栈跟踪,这是编译器崩溃而不是 joda 的失败断言。

REPL 在编译表达式时崩溃。

它看起来像 AbstractDateTime有一个过载 toString方法和重载解析在 @ToString 上崩溃通常的注释 toString() . (ToString 的符号丢失。)

但是stringOf(x: Any)只是调用 Object.toString() , 当然。

some known issues , 显然。 recent issue是固定的。

在 2.10.4 上:

scala> (dt: Any).toString
res0: String = 2014-05-14T11:56:21.794-07:00

scala> dt.toString
<console>:9: error: ambiguous reference to overloaded definition,
both method toString in class AbstractDateTime of type (x$1: String, x$2: java.util.Locale)String
and method toString in class AbstractDateTime of type (x$1: String)String
match expected type ?
dt.toString
^

scala> dt.toString() // crashes

2.10.3 比较颠簸和 claim error while loading DateTime, class file is broken .

崩溃发生在 2.11.0。

关于scala - 当 x.toString 失败时,ScalaRunTime.stringOf(x) 如何不失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23660990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com