作者NewSpec (新规格)
看板java
标题[问题] 为什麽Groovy可以使用字串作为方法名称?
时间Thu Mar 20 15:01:28 2014
Groovy可以很简单的使用字串作为方法名称, 例如:
def "this is method1"(){
println 'From method1'
}
然後这样叫用:
"this is method1"()
obj."this is method1"()
甚至这样也行
def '''this
is
method2'''(){
println 'From method2'
}
虽然是个有的时候算有用的feature
但我想了解这件事情究竟是怎麽完成的呢?
能否了解Groovy的版友能稍微解说一下, 感激不尽:)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.120.134.11
1F:→ swpoker:都是物件~Function只不过是个可执行的物件罢了 03/21 09:08