【问题标题】:Groovy, where is the difference? u.test != (u.test)Groovy,区别在哪里? u.test != (u.test)
【发布时间】:2020-09-25 07:23:08
【问题描述】:

区别在哪里 def foo = u.test + " " +u.test 工作正常,其中 def foo = (u.test) + " " +(u.test) 返回编译错误,如下所示:

unable to resolve class u.test
...
def foo = (u.test)+" "+(u.test)
          ^

1 error

在这个例子中,u 是我编写的一个实现地图接口的类。

【问题讨论】:

  • 可能是因为(class)用于类型转换。
  • 你使用的是什么版本的 Groovy?
  • @MichaelEaster 3.0.5
  • 将我的 groovy 版本更改为 2.5.13,现在可以正常工作了
  • 对我来说,代码适用于 groovy 3.0.5 和 2.5.13 - 也许你不小心忘记了第一个加号?! (u.test) " " + (u.test) 会尝试将 " " 转换为 u.test 类,导致你发布的错误

标签: groovy metaprogramming


【解决方案1】:

原因是我没有在我的依赖项中使用 groovy-all。在 2.5.13 中包含了一些类,这些类后来 (3.0.5) 在其他包中分离。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 2010-11-17
    • 2010-11-22
    • 2014-08-18
    • 2023-04-03
    相关资源
    最近更新 更多