Using Java Generics in Workflow Definition

Hi,

Is it possible to use Java Generics in workflow definitions like the following:

@WorkflowInterface
public interface TemporalGenericsTest<S, E> {...}

If so, what’s the best practice for managing and setting up workers/task queues? Based on my limited knowledge/experience with Temporal, it seems that we need to set up dedicated task queues for each type (combination) such as:

Worker ssWorker = factory.newWorker("String_And_String");
ssWorker.registerWorkflowImplementationTypes(TemporalGenericsTest.class);
ssWorker.registerActivitiesImplementations(new TemporalGenericsTestImpl<String, String>());

Worker seWorker = factory.newWorker("String_And_Event");
seWorker.registerWorkflowImplementationTypes(TemporalGenericsTest.class);
seWorker.registerActivitiesImplementations(new TemporalGenericsTestImpl<String, Event>());
...

Is there a more generic (no pun intended) approach?

Regards,

Eric

Generics are not supported for Activity and Workflow interfaces. What are you trying to achieve from the business point of view?

Thank you @maxim. I have a State Machine engine that makes use of generics for state and event objects, I was planning to create and expose the same interface APIs via Temporal workflow definition to minimize changes on the client side. I guess I could create a proxy with the same interface APIs and wrap state & event generics in concrete types before calling the workflow and perform type checking as well as casting before returning to the caller to achieve the same objective albeit with a bit more coding.

Makes sense. The reason we don’t support generics is that workflow and activity invocations are essentially cross process RPC. So all arguments should be serialized and deserialized. Because Java generics are not helpful in determining argument types at runtime through reflection we cannot do it.