軟件工程實踐者

          統(tǒng)計

          留言簿

          友情鏈結(jié)

          閱讀排行榜

          評論排行榜

          Groovy:Invalid duplicate class definition of class....The type xxx is already defined..

          當我們寫Groovy腳本代碼的時候,有時會發(fā)生編譯錯誤,如下:

          - Groovy:Invalid duplicate class definition of class XXX : The source XXXX\XXX.groovy contains at least two 
          definitions of the class XXX.
          - The type XXX is already defined

          原因在于Groovy會把.groovy代碼文件作為腳本或類定義來處理,例如如下代碼:

          class Order {
              def security
              def value
              private buy_sell(su, closure) {
                  security = su[0]
                  quantity = su[1]
                  closure()
              }
              def getTo() {
                  this
              }
          }
          def methodMissing(String name, args) {
              order.metaClass.getMetaProperty(name).setProperty(order, args)
          }
          def getNewOrder() {
              order = new Order()
          }

          Integer.metaClass.getShares = { -> delegate }

          Groovy會把上述代碼作為腳本處理,同時缺省用文件名來作為一個外圍類類包括整個腳本程序,此時,如果該文件名恰好也是Order的話,那么就會出現(xiàn)重復的類定義錯誤提示。
          解決辦法是將腳本文件名取另外一個不同的名字。

          posted on 2016-08-31 09:00 軟件工程實踐者 閱讀(1070) 評論(0)  編輯  收藏 所屬分類: 軟件設(shè)計

          主站蜘蛛池模板: 调兵山市| 谢通门县| 灵璧县| 稷山县| 大同市| 龙泉市| 松潘县| 惠水县| 河曲县| 东港市| 穆棱市| 庐江县| 兴国县| 清流县| 锡林郭勒盟| 巩留县| 安岳县| 渑池县| 炎陵县| 兴城市| 平顺县| 华容县| 涿鹿县| 湘潭市| 江源县| 醴陵市| 尖扎县| 孟州市| 桦甸市| 延津县| 治多县| 容城县| 曲水县| 观塘区| 博野县| 迭部县| 佛学| 裕民县| 会东县| 灵川县| 禹州市|