serialVersionUID问题 当前类没有继承Serializable接口,为什么还有定义serialVersionUID?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 另外,为什么有的内部嵌套类不定义serialVersionUID会出现警告但有的却不会?编译器时如何判断的? 1. 没有implements Serializable,有seerialVersionUID也没有错,就当是普通的一个field吧.2. 有的警告有的不警告各是怎么样的情况? 贴来看看. 有警告的private class FirstActionListener extends AbstractAction { /** * version id to make sure that different versions are compatible with each other */ //private static final long serialVersionUID = 1234567890123456789L; public void actionPerformed(ActionEvent e) { try { getActionListeners()[0].actionPerformed(e); } catch (ArrayIndexOutOfBoundsException out) { System.out.println("ArrayIndexOutOfBoundsException!"); System.out.println("Current GameButton hasn't added ActionListener!"); } } }没警告的private class QuitListener implements ActionListener { public void actionPerformed(ActionEvent e) { canClose(); } } AbstractAction继承了Serializable你跟踪源码就看到了 public abstract class AbstractAction implements Action, Cloneable, Serializable清楚了吧. 除继承Serializable接口外还有哪些情况要定义serialVersionUID例如下面的GameFrame类必须定义serialVersionUID是因为类中的方法调用了已经序列化的类的对象吗public class GameData implements Serializable{ private static final long serialVersionUID = 1234567890123456789L;.............................................}public class GameFrame extends JFrame//需定义serialVersionUID,否则警告{ public void writeGameDate() { ObjectOutputStream ............. }} public class GameFrame extends JFrame//需定义serialVersionUID,否则警告{ public void writeGameDate() { ObjectOutputStream ............. }}这个与是否调用了已经序列化的类对象无关,警告是因为:GameFrame extends JFrameJFrame extends FrameFrame extends WindowWindow extends ContainerContainer extends Componentpublic abstract class Component implements ImageObserver, MenuContainer, Serializable JWindow如何调用paint方法 静态 关于static和final 日期问题,请大家帮忙! 帮忙看看下面这点小代码?是不是因为jdk的版本造成的!(关于java.lang.Integer) 有一个算法问题搞得我很郁闷!(我真是猪脑子,这么简单的居然想不出来!!!) 问一个有关Jbuilder7 IDE的问题! SOS!!!救命啊! 关于画图的问题!!! 这个要求值50分吗? 有个不简单的正则,帮忙看看。 测试算法运行时间
{
/**
* version id to make sure that different versions are compatible with each other
*/
//private static final long serialVersionUID = 1234567890123456789L;
public void actionPerformed(ActionEvent e)
{
try
{
getActionListeners()[0].actionPerformed(e);
}
catch (ArrayIndexOutOfBoundsException out)
{
System.out.println("ArrayIndexOutOfBoundsException!");
System.out.println("Current GameButton hasn't added ActionListener!");
}
}
}
没警告的private class QuitListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
canClose();
}
}
{
private static final long serialVersionUID = 1234567890123456789L;
.............................................
}public class GameFrame extends JFrame//需定义serialVersionUID,否则警告
{
public void writeGameDate()
{
ObjectOutputStream .............
}
}
{
public void writeGameDate()
{
ObjectOutputStream .............
}
}这个与是否调用了已经序列化的类对象无关,警告是因为:
GameFrame extends JFrame
JFrame extends Frame
Frame extends Window
Window extends Container
Container extends Component
public abstract class Component implements ImageObserver, MenuContainer, Serializable