Groovy generic type that extends trait mismatch - not a valid substitute for the bounded parameter

Viewed 60

Code below is not compiling in Groovy 3.0.4 (although its fine with Groovy 2.5.0 and below)

Factory<SomeImpl> f = new Factory<>();

trait Base {}
class SomeImpl implements Base {}
class Factory<T extends Base> {}

Exact error which I get is:

The type SomeImpl is not a valid substitute for the bounded parameter <T extends Base> @ line 1, column 9.
Factory<SomeImpl> f = new Factory<>();

Changing Base from trait to interface allows the code to be compiled as expected and it works (like in Java).

Is trait somewhat different from the interface that does not allow us to do such constructs? or is it a bug in recent groovy versions?

0 Answers
Related