Anyone can help? I think I'm either misunderstanding or missing something obvious. My solution meets all the test criteria but fails to verify. I think I'm not using ItemInvocationHandler correctly.
Thanks in advance.
package com.codegym.task.task32.task3206;
import java.lang.reflect.Proxy;
/*
Generics for creating a proxy object
*/
public class Solution {
public static void main(String[] args) {
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 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);
}
public Object getProxy(Class ReturnClass, Class... Classes) {
Class<?>[] interfaces = new Class[Classes.length + 1];
interfaces[0] = ReturnClass;
System.arraycopy(Classes, 0, interfaces, 1, Classes.length);
Object proxy;
proxy = Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces, new ItemInvocationHandler(new ItemImpl()));
return proxy;
}
}