请教一个关于Class.forName的问题。

baoma2000 2003-11-20 05:06:03
1 Class cls = Class.forName(jndiName);
2 BusinessBean SessionBean = (BusinessBean)cls.newInstance();
3 br = SessionBean.execute(pm);

BusinessBean的定义:
public interface BusinessBean {
public BusinessResult execute(int pm);
}
第1行能通过,第2行就不能了。请问该如何修改呢?
...全文
27 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
baoma2000 2003-11-20
  • 打赏
  • 举报
回复
有点明白了,谢谢各位了。
public class BusinessBean {
//constructor here

public abstract BusinessResult execute(int pm);
}
这里也用BusinessBean名字没有问题社。
takecare 2003-11-20
  • 打赏
  • 举报
回复
看来还是实践是检验真理的唯一标准。
哈哈
takecare 2003-11-20
  • 打赏
  • 举报
回复
我编译过你的程序的,没有问题,只要你抓了那些异常,所以我的1楼的回答是没有什么根据的(本来像是不是interface 不能 newInstance())。
takecare 2003-11-20
  • 打赏
  • 举报
回复
public Object newInstance()
throws InstantiationException,
IllegalAccessExceptionCreates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized.
If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException.


Returns:
a newly allocated instance of the class represented by this object.
Throws:
IllegalAccessException - if the class or its nullary constructor is not accessible.
InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.
ExceptionInInitializerError - if the initialization provoked by this method fails.
SecurityException - if there is no permission to create a new instance.
takecare 2003-11-20
  • 打赏
  • 举报
回复
是不是没有抓
java.lang.InstantiationException
exception
xiaohaiz 2003-11-20
  • 打赏
  • 举报
回复
把 String jndiName 内容告诉大家是什么?
Yssss1980 2003-11-20
  • 打赏
  • 举报
回复
你实例化的类是什么类啊

出什么错了,ClassNotFind?

takecare 2003-11-20
  • 打赏
  • 举报
回复
你的接口定义了,但是为什么没有实现呢?是没有贴出来呢还是别的?
baoma2000 2003-11-20
  • 打赏
  • 举报
回复
还不是很明白?
ddbean 2003-11-20
  • 打赏
  • 举报
回复
缺少构造函数
takecare 2003-11-20
  • 打赏
  • 举报
回复
public class BusinessBean {
//constructor here

public abstract BusinessResult execute(int pm);
}

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧