W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
本節(jié)討論Groovy的Extract參數(shù)(提取參數(shù))重構(gòu)。通過此重構(gòu),您可以執(zhí)行以下操作:
使用示例一:
重構(gòu)前:
class Cat {
Cat cat = new Cat()
def makePestOfItself(){
print ("miaou!!!!!!!!")
}
def makeTroubles(){
if (makePest){
makePestOfItself()
}
}
}
重構(gòu)之后:
class Cat {
Cat cat = new Cat()
def makePestOfItself(String warning){
print (warning)
}
def makeTroubles(){
if (makePest){
makePestOfItself("miaou!!!!!!!!")
}
}
}
使用示例二:
使用重構(gòu)前:
class Bar {
def foo = {
print 'H<caret here>ello, world!'
}
}
new Bar().foo()
new Bar().foo.call()
使用重構(gòu)后:
class Bar {
def foo = { String s ->
print s
}
}
new Bar().foo('Hello, world!')
new Bar().foo.call('Hello, world!')
在Groovy中提取參數(shù)的操作步驟如下所示:
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: