sdk-java icon indicating copy to clipboard operation
sdk-java copied to clipboard

Support generics on workflow methods

Open rorueda opened this issue 5 months ago • 4 comments

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:

  1. Use of a TypeVariable that is specified.
public interface QueryBase<T> {
  @QueryMethod
  T query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
  1. Use of a TypeVariable that is bound.
public interface QueryBase<T> {
  @QueryMethod
  T query();
}
@WorkflowInterface
public interface Workflow<T extends WorkflowState> extends QueryBase<T> {}
  1. Use of a TypeVariable in a ParameterizedType.
public interface QueryBase<T> {
  @QueryMethod
  Wrapper<T> query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
  1. Use of a TypeVariable in a GenericArrayType.
public interface QueryBase<T> {
  @QueryMethod
  T[] query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
  1. Use of a TypeVariable in a GenericArrayType, in a ParameterizedType.
public interface QueryBase<T> {
  @QueryMethod
  Wrapper<T[]> query();
}
@WorkflowInterface
public interface Workflow extends QueryBase<WorkflowState> {}
  1. Use of a TypeVariable as an upper bound of a WildcardType in a ParameterizedType.
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

  1. Closes https://github.com/temporalio/sdk-java/issues/1106 https://github.com/temporalio/sdk-java/issues/1107
  2. How was this tested:

Unit tests.

  1. Any docs updates needed?

Maybe it is good to point out what is supported at workflow-parameters and workflow-return-values.

rorueda avatar Aug 28 '24 18:08 rorueda