groovy @CompileStatic + 泛型 编译出错

错误提示如下

Execution failed for task ‘:compileGroovy’.
BUG! exception in phase ‘instruction selection’ in source unit ‘xxxx/xxx/HttpClientRestApi.groovy’ Expected earlier checking to detect generics parameter arity mismatch
Expected: com.telecwin.gcl.client.api.Response< T >
Supplied: com.telecwin.gcl.client.api.Response<java.lang.String,com.telecwin.gcl.client.api.ResponseCode>

导致错误的代码行终于找到了:

Response fail = new Response<>(code: ERROR_SYS)

改成

Response fail = new Response(code: ERROR_SYS)

问题解决。
这个问题无论在 groovy2.5.9 还是 groovy3.0.2 都存在。

估计这个是 groovy 的一个bug。

另外 groovy3 开始支持 java interface 中的 default method 了,尽量少用 trait,貌似容易问题。

发布了63 篇原创文章 · 获赞 25 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/yangbo_hr/article/details/105066282