sdk-java
sdk-java copied to clipboard
Support generics on workflow methods
What was changed
Support for generics on workflow methods, both in parameters and return types. The aim is to support use cases like the following:
- Use of a
TypeVariable
that is specified.
public interface QueryBase<T> {
@QueryMethod
T query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
- Use of a
TypeVariable
that is bound.
public interface QueryBase<T> {
@QueryMethod
T query();
}
@WorkflowInterface
public interface Workflow<T extends WorkflowState> extends QueryBase<T> {}
- Use of a
TypeVariable
in aParameterizedType
.
public interface QueryBase<T> {
@QueryMethod
Wrapper<T> query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
- Use of a
TypeVariable
in aGenericArrayType
.
public interface QueryBase<T> {
@QueryMethod
T[] query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
- Use of a
TypeVariable
in aGenericArrayType
, in aParameterizedType
.
public interface QueryBase<T> {
@QueryMethod
Wrapper<T[]> query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
- Use of a
TypeVariable
as an upper bound of aWildcardType
in aParameterizedType
.
public interface QueryBase<T> {
@QueryMethod
Wrapper<? extends T> query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
Why?
To be able to reuse a base interface in all my workflow interfaces. Together, the two issues mentioned below in the checklist make this currently impossible.
Reading the comments on the first issue, I get that this support might be controversial, but I couldn't live without it. It would be great to have this merged, so others can benefit and I don't need to keep a fork.
Checklist
- Closes https://github.com/temporalio/sdk-java/issues/1106 https://github.com/temporalio/sdk-java/issues/1107
- How was this tested:
Unit tests.
- Any docs updates needed?
Maybe it is good to point out what is supported at workflow-parameters and workflow-return-values.