今天编程中,遇到了这么一个问题,虽然解决了,但是百思不得其解。问题的产生:
程序抛出java.lang.ClassCastException
解决方案:
把代码中的“return( new IMServiceImpl( serviceName ) );”
改为
IMServiceImpl imServiceImpl;
imServiceImpl = new IMServiceImpl( ServiceName );
return imServiceImpl;就好了,难道对象有没有名字竟然造成了这么大的区别?
程序抛出java.lang.ClassCastException
解决方案:
把代码中的“return( new IMServiceImpl( serviceName ) );”
改为
IMServiceImpl imServiceImpl;
imServiceImpl = new IMServiceImpl( ServiceName );
return imServiceImpl;就好了,难道对象有没有名字竟然造成了这么大的区别?
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:
Object x = new Integer(0);
System.out.println((String)x);
你的错误的话,应该把全部代码帖出来,应该就知道了那里的问题了 !
IMServiceImpl imServiceImpl;
imServiceImpl = new IMServiceImpl( ServiceName );
return imServiceImpl;难道有什么区别吗?
或者说,这两种方式产生的对象类型竟然不一样?
很邪门啊。
sorry
IMService接口的对象,而IMServiceImple就是符合
该要求的东西.嗯,如果这个对象需要序列话,通过RMI传输,有没有
名字有区别吗?