groovy - @TypeChecked failure over generic type argument -
i have mixed groovy/java environment simple manager hierarchy:
public abstract class homebean<t extends baseentity> { private t instance; public t getinstance() { if (instance == null) { if (id != null) { instance = loadinstance(); } else { instance = createinstance(); } } return instance; } protected void setinstance(t instance) { this.instance = instance; } }
and in taskmanager.groovy:
@typechecked class taskmanager extends homebean<task> implements serializable { void dosomething() { instance.compute() } }
the problem i'm seeing groovy compiler assumes instance
of type baseentity
, ignores restriction made taskmanager
.
is design or can somehow make compiler aware of additional type information?
edited add: i've verified still happening groovy-2.1.7, despite hope fixed in groovy-5981.
edited add: workaround, i'm casting instance this:
@typechecked class taskmanager extends homebean<task> { void dosomething() { currenttask.compute() } task getcurrenttask() { instance task } }
but that's needless piece of duplication i'd rid of.
Comments
Post a Comment