我有一个复杂的循环通用结构:
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){...}
}
我希望-somehow-将这3个通用参数组合成一个,并轻松声明:
class LoadBalanceProcessor<JobTypeGroup>{
@Inject
Provider<JobDao<JobTypeGroup>> jobDaoProvider;
long getTimeToWait(/* ?? */) {...}
}
如何声明JobTypeGroup参数指向Job-Recipient-Event三元组?我可以改变原来的工作声明。