源文件:
/**
*}
在工程bin目录下使用 rmic 命令
反编译以后
package rmi;
import java.lang.reflect.Method;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.UnexpectedException;
import java.rmi.server.RemoteObject;
import java.rmi.server.RemoteRef;
import java.rmi.server.RemoteStub;
//实现和真实对象相同的接口
// RemoteStub
类是客户机 stub 的公共超类,提供支持大量远程引用语义的框架
public final class HelloImpl_Stub extends RemoteStub
implements IHello, Remote
{
private static final long serialVersionUID = 2L;
private static Method $method_helloWorld_0;
private static Method $method_sayHelloToSomeBody_1;
static
{
try
{
$method_helloWorld_0 = Remote.class.getMethod("helloWorld", new Class[0]);
$method_sayHelloToSomeBody_1 = tmp50_47.getMethod("sayHelloToSomeBody", new Class[] { String.class });
}
catch (NoSuchMethodException localNoSuchMethodException)
{
throw new NoSuchMethodError("stub class initialization failed");
}
}
public HelloImpl_Stub(RemoteRef paramRemoteRef)
{
super(paramRemoteRef);
}
public String helloWorld()
throws RemoteException
{
Object localObject;
try
{
//调用真实对象的helloword方法
localObject = this.ref.invoke(this, $method_helloWorld_0, null, 32013462L);
return ((String)localObject);
}
catch (RuntimeException localRuntimeException)
{
throw localRuntimeException;
}
catch (RemoteException localRemoteException)
{
throw localRemoteException;
}
catch (Exception localException)
{
throw new UnexpectedException("undeclared checked exception", localException);
}
}
public String sayHelloToSomeBody(String paramString)
throws RemoteException
{
try
{
Object localObject = this.ref.invoke(this, $method_sayHelloToSomeBody_1, new Object[] { paramString }, -1641805534L);
return ((String)localObject);
}
catch (RuntimeException localRuntimeException)
{
throw localRuntimeException;
}
catch (RemoteException localRemoteException)
{
throw localRemoteException;
}
catch (Exception localException)
{
throw new UnexpectedException("undeclared checked exception", localException);
}
}
}
显然 HelloImpl_Stub 是 HelloImpl 的一个代理。
动态生成HelloImpl_Stub 的过程, 就是动态创建代理的过程。