Class cls = obj.getClass(); String classname = cls.getName(); ClassLoader cl = cls.getClassLoader(); try { Class scls = cl.loadClass(classname + "_Stub");  Class[] stubprototype = new Class[] { RemoteRef.class }; Constructor con = scls.getConstructor(stubprototype); return (Remote)(con.newInstance(new Object[]{obj})); } catch (Exception e) {}
Remote stub = (Remote)stubs.get(obj);  if (stub == null)
  public static Remote toStub(Remote obj) throws NoSuchObjectException   {    Class cls = obj.getClass();    String classname = cls.getName();    ClassLoader cl = cls.getClassLoader();    try       {	Class scls = cl.loadClass(classname + "_Stub");	// JDK 1.2 stubs	Class[] stubprototype = new Class[] { RemoteRef.class };	Constructor con = scls.getConstructor(stubprototype);	return (Remote)(con.newInstance(new Object[]{obj}));      }    catch (Exception e) {}    throw new NoSuchObjectException(obj.getClass().getName());  }