Whoever wrote that type inference documentation should be commended, it is very 
good and very thorough. Very understandable and easy to read yet detailed 
enough even to satisfy the curiosity of “how did they get that to work?”. In 
fact, since moving out of Codehaus wiki, the documentation is far improved. 
From a user’s perspective I was concerned at first that a rewrite would take 
forever, but it didn’t and these new docs continue to impress each time I open 
them.

Jason

From: Cédric Champeau [mailto:cedric.champ...@gmail.com]
Sent: Wednesday, August 26, 2015 4:19 AM
To: users@groovy.incubator.apache.org
Subject: Re: type checked with generics issue

Hi Jamie,

See 
http://docs.groovy-lang.org/latest/html/documentation/#_variables_vs_fields_in_type_inference
 for an explanation.

2015-08-26 10:14 GMT+02:00 Jamie Echlin 
<jamie.ech...@gmail.com<mailto:jamie.ech...@gmail.com>>:
I'm confused about the type checking in one instance. Take this:

class Foo {
    String getBar() { "bar" }
}

@TypeChecked
class TestFoo {

    def foo = new Foo()

    void test() {
        assert foo.bar == "bar"
    }
}

If the def of foo is within the test() method it's fine, but where it is it 
seems not to be able to resolve the type (cannot resolve symbol "bar"). Why 
can't it infer the type - I don't see what will change the type between 
initialisation and the when the method is called.

cheers, jamie



----------------------------------------------------------------------
This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.

Reply via email to