日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【错误记录】Groovy 注入方法报错 ( Cannot add new method [hello] for arguments [[]]. It already exists )

發(fā)布時(shí)間:2025/6/17 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【错误记录】Groovy 注入方法报错 ( Cannot add new method [hello] for arguments [[]]. It already exists ) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • 一、報(bào)錯(cuò)信息
  • 二、解決方案





一、報(bào)錯(cuò)信息



使用 MetaClass 為類注入方法時(shí) , 如果注入的方法與類中原有的方法有沖突 ,

class Student {def name;def hello() {println "Hello " + name} }// 向 Student 類注入 hello 方法 Student.metaClass.hello << {println delegateprintln "Hello ${delegate.name}" }

執(zhí)行上述方法 , 會(huì)有如下報(bào)錯(cuò) ;

報(bào)錯(cuò)信息 :

Caught: groovy.lang.GroovyRuntimeException: Cannot add new method [hello] for arguments [[]]. It already exists! groovy.lang.GroovyRuntimeException: Cannot add new method [hello] for arguments [[]]. It already exists!at Groovy.run(Groovy.groovy:11)





二、解決方案



如果使用 Category 分類的方式注入方法 , 注入的方法可以與類中原來的方法相同 , 參考 【Groovy】MOP 元對(duì)象協(xié)議與元編程 ( 方法注入 | 使用 @Category 注解進(jìn)行方法注入 | 分類注入方法查找優(yōu)先級(jí) ) 博客 ;

使用 MetaClass 的方式注入方法 , 注入的方法不可與原來的方法沖突 , 否則就會(huì)報(bào)上述錯(cuò)誤 ; 參考 【Groovy】MOP 元對(duì)象協(xié)議與元編程 ( 方法注入 | 使用 MetaClass 進(jìn)行方法注入普通方法 ) 博客 ;

總結(jié)

以上是生活随笔為你收集整理的【错误记录】Groovy 注入方法报错 ( Cannot add new method [hello] for arguments [[]]. It already exists )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。