背景
出现了相同类castException
分析
首先确定出现相同类的castException比如是由于classloader不同造成的。
一个class是否相同取决于两个因素
classloader相同
class文件相同
即不同classloader解释出来的class是不同的class
我们在学习jdbc的时候常见的使用
/**
* Returns the {@code Class} object associated with the class or
* interface with the given string name. Invoking this method is
* equivalent to:
*
*
* {@code Class.forName(className, true, currentLoader)}
*
*
* where {@code currentLoader} denotes the defining class loader of
* the current class.
*
*
For example, the following code fragment returns the
* runtime {@code Class} descriptor for the class named
* {@code java.lang.Thread}:
*
*
* {@code Class t = Class.forName("java.lang.Thread")}
*
*
* A call to {@code forName("X")} causes the class named
* {@code X} to be initialized.
*
* @param className the fully qualified name of the desired class.
* @return the {@code Class} object for the class with the
* specified name.
* @exception LinkageError if the linkage fails
* @exception ExceptionInInitializerError if the initialization provoked
* by this method fails
* @exception ClassNotFoundException if the class cannot be located
*/
public static Class> forName(String className)
throws ClassNotFoundException {
return forName0(className, true, ClassLoader.getCallerClassLoader());
}
从上面我们可以了解不同的classloader解释的相同class也无法互相转换
这样我们把目标放在d