@Test public void findClass() throws Exception { OneClassLoader stringLoader = new OneClassLoader(String.class.getName(), getClass().getClassLoader()); OneClassLoader testLoader = new OneClassLoader(getClass().getName(), getClass().getClassLoader()); LinkedClassLoader classLoader = new LinkedClassLoader(stringLoader, testLoader); assertSame(String.class, classLoader.findClass(String.class.getName())); assertSame(getClass(), classLoader.findClass(getClass().getName())); assertThrows(ClassNotFoundException.class, () -> classLoader.findClass(Test.class.getName())); }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { Class<?> clazz = null; for (ClassLoader classLoader : classLoaders) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { } } if (clazz == null) { throw new ClassNotFoundException(name); } return clazz; }
LinkedClassLoader extends ClassLoader { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { Class<?> clazz = null; for (ClassLoader classLoader : classLoaders) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { } } if (clazz == null) { throw new ClassNotFoundException(name); } return clazz; } }
LinkedClassLoader extends ClassLoader { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { Class<?> clazz = null; for (ClassLoader classLoader : classLoaders) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { } } if (clazz == null) { throw new ClassNotFoundException(name); } return clazz; } LinkedClassLoader(ClassLoader... classLoaders); }
LinkedClassLoader extends ClassLoader { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { Class<?> clazz = null; for (ClassLoader classLoader : classLoaders) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { } } if (clazz == null) { throw new ClassNotFoundException(name); } return clazz; } LinkedClassLoader(ClassLoader... classLoaders);  }
LinkedClassLoader extends ClassLoader { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { Class<?> clazz = null; for (ClassLoader classLoader : classLoaders) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { } } if (clazz == null) { throw new ClassNotFoundException(name); } return clazz; } LinkedClassLoader(ClassLoader... classLoaders);   }