private static Collection4 collectNames(Class[] classes) { Collection4 names = new Collection4(); for (int classIdx = 0; classIdx < classes.length; classIdx++) { names.add(classes[classIdx].getName()); } return names; }
public static void main(String[] args) throws Exception { ClassLoader parent = ExcludingClassLoader.class.getClassLoader(); String excName = ExcludingClassLoader.class.getName(); Collection4 excluded = new Collection4(); ClassLoader incLoader = new ExcludingClassLoader(parent, excluded); System.out.println(incLoader.loadClass(excName)); excluded.add(excName); try { System.out.println(incLoader.loadClass(excName)); } catch (ClassNotFoundException exc) { System.out.println("Ok, not found."); } }