Thanks Cedric, that's interesting. I never really followed this advice:

This is one of the reasons why we recommend to use typed fields. While using def for local variables is perfectly fine thanks to type inference, this is not the case for fields, which also belong to the public API of a class, hence the type is important.

I guess I will now...

On Wed, Aug 26, 2015 at 9:19 AM, Cédric Champeau <cedric.champeau@gmail.com> wrote:
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.echlin@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