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 BaseAdapter<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?