【发布时间】:2013-02-27 06:51:29
【问题描述】:
所以,我正在使用 Java,试图将 java.sql.ResultSet 转换为我自己的类 MyResultSet
代码如下: MyResultSet.java
public class MyResultSet implements java.sql.ResultSet{
//There are a bunch of Implemented Methods here. None of them have any custom code, They are all unchanged. Just didn't want to put huge code in here.
}
我尝试使用的代码
ResultSet r = getResultSet();
return (MyResultSet)r;
每当我运行它时,我都会收到“ClassCastException”。
有人可以向我解释如何转换为已实现的类吗?..
【问题讨论】:
-
getResultSet()的返回类型是什么? -
那么
getResultSet()是什么? -
可能是
java.sql.ResultSet -
它是
java.sql.ResultSet。这只是示例代码。 -
看来你必须阅读一些关于类和继承的理论 =) 你不能将任何类强制转换为你在 java 中的实现。
标签: java class classcastexception