2

我有一个复杂的循环通用结构:

interface Job<J extends Job<J,R,E>, R extends Recipient<J,R,E>, E extends Event<J,R,E>> { }
interface Recipient<J extends Job<J,R,E>, R extends Recipient<J,R,E>, E extends Event<J,R,E> { }
interface Event<J extends Job<J,R,E>, R extends Recipient<J,R,E>, E extends Event<J,R,E> { }

这个设计是修剪复制粘贴代码的结果。通过这种方式它是类型安全的,但很难使用:

class EmailJob implements Job<EmailJob, EmailRecipient, EmailEvent> { }
class VoiceCallJob implements Job<VoiceCallJob, VoiceCallRecipient, VoiceCallEvent> { }
//Recipient and Event classes omitted.

下面是一个示例,工作独立类:

class LoadBalanceProcessor<J extends Job<J,R,E>, R extends Recipient<J,R,E>, E extends Event<J,R,E>> {
    @Inject
    Provider<JobDao<J extends Job<J,R,E>, R extends Recipient<J,R,E>, E extends Event<J,R,E>>> jobDaoProvider;
    long getTimeToWait(J job, R recipient){...}
}

我希望以某种方式将这 3 个通用参数组合为一个,并轻松声明它们:

class LoadBalanceProcessor<JobTypeGroup>{
    @Inject
    Provider<JobDao<JobTypeGroup>> jobDaoProvider;
    long getTimeToWait(/* ?? */) {...}
}

如何声明指向 Job-Recipient-Event 三元组的 JobTypeGroup 参数之类的东西?我可以更改原来的工作声明。

4

0 回答 0