为什么在扩展RuntimeException时我们需要serialVersionUID? RuntimeException是一个可序列化的类吗?
public class DataNotFoundException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1;
public DataNotFoundException(String str)
{
super(str);
}
}
解决方法:
RuntimeException扩展了Exception.异常扩展为Throwable. Throwable实现Serializable.所以DataNotFoundException也是Serializable