国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Groovy中Mixin注入

2019-11-08 01:55:08
字體:
來源:轉載
供稿:網友

Groovy中Mixin注入

Mixin在可以在運行時將其他類的實現導入進來。1、通過Mixin注解。
class Helper {	def work() {		PRintln "$name is working"	}}@Mixin(Helper)class AGroovyClass {	def getName() { "AGroovyClass" }}new AGroovyClass().work() // AGroovyClass is working2、調用類的Mixin方法。
class Helper {	def work() {		println "$name is working"	}}class AGroovyClass {	def getName() { "AGroovyClass" }}AGroovyClass.mixin Helpernew AGroovyClass().work() // AGroovyClass is working3、在類的metaClass中調用mixin方法。
class Helper {	def work() {		println "$name is working"	}}class AGroovyClass {	def getName() { "AGroovyClass" }}AGroovyClass.metaClass.mixin Helpernew AGroovyClass().work() // AGroovyClass is working4、多個類mixin。
class Helper {    def work() {        println "$name is working"    }}class Num {    def add(val1, val2) {        println val1 + val2    }}class AGroovyClass {    def getName() { "AGroovyClass" }}AGroovyClass.mixin HelperAGroovyClass.mixin Num// AGroovyClass.metaClass.mixin Helper// AGroovyClass.metaClass.mixin Numnew AGroovyClass().work() // AGroovyClass is workingnew AGroovyClass().add(11, 12) // 23
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 威海市| 东方市| 绥棱县| 鹤山市| 永泰县| 京山县| 卢龙县| 龙井市| 柘城县| 六枝特区| 巴塘县| 沐川县| 蓬莱市| 茶陵县| 台东市| 福泉市| 修武县| 志丹县| 雷州市| 舟曲县| 新竹县| 南平市| 环江| 金湖县| 夹江县| 江西省| 洛浦县| 宁乡县| 潮安县| 察雅县| 三河市| 尚志市| 翼城县| 盘锦市| 盐城市| 临夏县| 连平县| 望都县| 钟山县| 慈溪市| 思茅市|