>... pairs) {
initDelegateMethods(pairs);
Class>[] interfaces = new Class [pairs.length];
int count = 0;
for (Tuple2> tuple2 : pairs) {
interfaces[count++] = tuple2.b;
}
return Proxy.newProxyInstance(interfaces[0].getClassLoader(), interfaces, new MixinHandler());
}
}
// ............................................interface
interface Clock {
public void clock();
}
class ClockImp implements Clock {
public void clock() {
System.out.println("Clocking....");
}
}
interface Calendar {
public void calendar();
}
class CalendarImp implements Calendar {
public void calendar() {
System.out.println("Calending....");
}
}
interface Timer {
public void printTime();
}
class Watch implements Timer {
public void printTime() {
System.out.println(new Date());
}
}
/*
* use interface to produce effect of mixing, to make EleWatch have Watch,Clock
* Calendar functions
*/
class EleWatch extends Watch implements Clock, Calendar {
private Clock clock = new ClockImp();
private Calendarcalendar= new CalendarImp();
public void calendar() {
calendar.calendar();
}
public void clock() {
clock.clock();
}
}