Here you can find the source of getInterfaceInstance(Class
static <T> T getInterfaceInstance(Class<T> interfaceType) throws InstantiationException, IllegalAccessException
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { private static final Map<Class<?>, Class<?>> interfaceImplementations = new HashMap<>(); static <T> T getInterfaceInstance(Class<T> interfaceType) throws InstantiationException, IllegalAccessException { Class impl = interfaceImplementations.get(interfaceType); if (impl == null) { throw new InstantiationException("Cannot instantiate interface [ " + interfaceType.getName() + "]"); }/*w w w . j a va2 s . c o m*/ return (T) impl.newInstance(); } }