public static Runnable newServlet(String name, Socket socket)
{
Runnable m = null;
Constructor c = null;
try
{
c = Class.forName(name).getConstructor(new Class[] { Socket.class });
m = (Runnable)c.newInstance(new Object[] { socket });
PPGMain.echo("HandlerServletPool.newServlet:" + name + "=>" + m.toString());
}
catch (Exception e) {
PPGMain.echo("HandlerServletPool.newServlet:" + name + "|fail,as exception:" +
e.getMessage());
}
return m;
}
使用了Java的反射来获取socket实例,
java中new Class[]{Socket.class}写法的意思
最新推荐文章于 2021-02-16 12:51:54 发布