mardi 6 juin 2017

how to dynamically create an object from a class that implements some interface?

I know Proxy but I want the returned object be an instance of my class for example the below code print true

public class test
{
    public static void main(String[] args)
    {

        Object t = Proxy.newProxyInstance(test.class.getClassLoader(), new Class[0], new fr());
        System.out.println(t instanceof test);
    }
}

class fr implements InvocationHandler{
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
        // TODO Auto-generated method stub
        return null;
    }
}





Aucun commentaire:

Enregistrer un commentaire