[
https://issues.apache.org/jira/browse/GROOVY-8214?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16036778#comment-16036778
]
Daniil Ovchinnikov commented on GROOVY-8214:
All cases work when value returned from property is a {{Closure}}. In
{{Closure}} cases explicit method takes precedence:
{code}
class A {
def getFoo() { return { "closure" } }
def foo() { "method" }
}
println new A().foo() // method
{code}
I see no reason not to allow the same behaviour for all objects with
{{.call()}} defined.
There is special handling for closures in
{{groovy.lang.MetaClassImpl#invokePropertyOrMissing}}. In may be replaced with
something like this (pseudocode):
{code}
if (/*necessary checks*/) return invokeMethod(value, "call", args)
{code}
> Implicit .call is inconsistent
> --
>
> Key: GROOVY-8214
> URL: https://issues.apache.org/jira/browse/GROOVY-8214
> Project: Groovy
> Issue Type: Bug
>Reporter: Daniil Ovchinnikov
>
> {code}
> interface Callable {
> def call()
> }
> def callable = new Callable() {
> def call() { println "callable local var" }
> }
> callable.call()
> callable()
> class ClassWithCallableField {
> public ppp = new Callable() {
> def call() { println "callable field" }
> }
> }
> def cwcp = new ClassWithCallableField()
> cwcp.ppp.call()
> cwcp.ppp() // MME
> def foo(Callable p) {
> p.call()
> p()
> }
> foo new Callable() {
> def call() { println "callable parameter" }
> }
> class ClassWithCallableGetter {
> def getGetter() {
> new Callable() {
> def call() { println "callable getter" }
> }
> }
> }
> def cwcg = new ClassWithCallableGetter()
> cwcg.getter.call()
> cwcg.getter() // MME
> class ClassWithCallableFieldInside {
> public bbb = new Callable() {
> def call() { println "callable field inside class" }
> }
> def foo() {
> bbb.call()
> bbb()
> }
> }
> new ClassWithCallableFieldInside().foo()
> class ClassWithCallableGetterInside {
> def getGetter() {
> new Callable() {
> def call() { println "callable getter inside class" }
> }
> }
> def foo() {
> getter.call()
> getter() // MME
> }
> }
> new ClassWithCallableGetterInside().foo()
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)