I have tried so many times with so many diffirent ways, but this task still cann't verified. please help, :(.
package com.codegym.task.task32.task3206;
import java.lang.reflect.Proxy;
import java.util.*;
/*
Generics for creating a proxy object
*/
public class Solution {
public static void main(String[] args) {
System.out.println(Item.class);
Solution solution = new Solution();
test(solution.getProxy(Item.class)); // true false false
test(solution.getProxy(Item.class, Small.class)); // true false true
test(solution.getProxy(Item.class, Big.class, Small.class));// true true true
test(solution.getProxy(Big.class, Small.class)); // true true true, because Big inherits Item
test(solution.getProxy(Big.class)); // true true false, because Big inherits Item
}
public Object getProxy(Class ReturnClass, Class... items){
List<Class> interfaces = new ArrayList<>();
interfaces.add(ReturnClass);
for (Class clazz : items) {
interfaces.add(clazz);
}
//Collections.addAll(Arrays.asList(items));
Object proxy = Proxy.newProxyInstance(ReturnClass.getClassLoader(),
interfaces.toArray(new Class[interfaces.size()]),
new ItemInvocationHandler());
return proxy;
}
private static void test(Object proxy) {
boolean isItem = proxy instanceof Item;
boolean isBig = proxy instanceof Big;
boolean isSmall = proxy instanceof Small;
System.out.format("%b %b %b\n", isItem, isBig, isSmall);
}
}