tags:

views:

39

answers:

1

Groovy seems to be unable to compile a class where I've derived from a Generic base class and overloaded a method returning a generic array. The same example in Java appears to compile correctly, which is surprising as I expected Groovy to have source-level compatibility [ref].

This can be reproduced with the following adapter example. This example can also be executed online at the awesome Groovy Web Console.

class Person {}

​abstract class Base​Adapter<T> {
    public T[] getAll() {
        return getAllInternal();
    }

    protected abstract T[] getAllInternal()
}

class PersonAdapter extends BaseAdapter<Person> {
    protected Person[] getAllInternal() {
        return new Person[0];
    }
}​

Compiling this produces the message:

Script1.groovy: 12: The return type of Person[] getAllInternal() in PersonAdapter is incompatible with [Ljava.lang.Object; getAllInternal() in BaseAdapter
. At [12:5]  @ line 12, column 5.
    protected Person[] getAllInternal() {
    ^

1 error

Have I got the syntax incorrect? Or, is this a Groovy issue?

+1  A: 

I expected Groovy to have source-level compatibility.

The source-level compatibility is maybe 90% but not perfect (nor is this a goal).

Have I got the syntax incorrect? Or, is this a Groovy issue?

Probably a bug. Please file a bug report.

Peter Niederwieser
Thanks Peter, will do.
David Padbury