`

@SuppressWarnings("serial")与private static final long serialVersionUID = 1L的区别

 
阅读更多
@SuppressWarnings("serial")指的是关闭类或方法级别的编译器警告

private static final long serialVersionUID = 1L;对某些对象进行序列化,让它们离开内存空间,入住物理硬盘

详细如下:



J2SE 提供的一个批注是 @SuppressWarnings。该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默。

常使用 @SuppressWarnings({"unchecked","serial"})和@SuppressWarnings("serial")



@SuppressWarnings("serial")指的是关闭类或方法级别的编译器警告

serial 当在可序列化的类上缺少 serialVersionUID 定义时的警告

警告定义如下:

deprecation 使用了不赞成使用的类或方法时的警告
unchecked 执行了未检查的转换时的警告,例如当使用集合时没有用泛型 (Generics) 来指定集合保存的类型。
fallthrough 当 Switch 程序块直接通往下一种情况而没有 Break 时的警告。
path 在类路径、源文件路径等中有不存在的路径时的警告。 
serial 当在可序列化的类上缺少 serialVersionUID 定义时的警告。 
finally 任何 finally 子句不能正常完成时的警告。
all 关于以上所有情况的警告。





private static final long serialVersionUID = 1L;

序列化就是为解决这种问题的,保证数据传输的稳定性,(当然序列化不止这一种用途),Model层的序列化主要是把实体类序列化到本地,这样客户端一旦访问数据库,(即数据)就被序列化到本地了,
model是一个在内存中存储和传输数据的对象,
序列化后方便远程传输和硬盘保存,如果你有这个需求的话,
分享到:
评论

相关推荐

    人民币大写转换

    public static final String EMPTY = ""; public static final String ZERO = "零"; public static final String ONE = "壹"; public static final String TWO = "贰"; public static final String THREE = "叁...

    @SuppressWarnings

    serial 当在可序列化的类上缺少 serialVersionUID 定义时的警告。 finally 任何 finally 子句不能正常完成时的警告。 all 关于以上所有情况的警告。 @SuppressWarnings 批注允许您选择性地取消特定代码段(即,类或...

    ssh 万能类分页系统,可复用!

    private static final long serialVersionUID = 1L; private List<DUser> list;//要返回的页面记录列表 private int allRow;//总记录数 private int totalPage;//总页数 private int currentPage;//当前页 ...

    BluetoothDemo

    private static final int REQUEST_ENABLE = 0x1; private static final int REQUEST_EX = 1; /* 请求能够被搜索 */ private static final int REQUEST_DISCOVERABLE = 0x2; private List<BluetoothDevice> _...

    java编写根据模板导出excel

    private static final long serialVersionUID = 1L; private String filename; @SuppressWarnings("rawtypes") public String export() throws Exception { String templateFile = "18.xls"; // String sql...

    关于@SuppressWarnings("uncheck ")(转)

    关于@SuppressWarnings("uncheck ")

    BluetoothDemoV1.2

    private static final int REQUEST_ENABLE = 0x1; private static final int REQUEST_EX = 1; /* 请求能够被搜索 */ private static final int REQUEST_DISCOVERABLE = 0x2; private List<BluetoothDevice> _...

    Java分组、分页源码

    public static final int PAGE_SIZE = 5; // 每页记录数 public static final int GROUP_SIZE = 5; // 每组显示的页数 private List<ClaimVoucher> list;// 要返回的某一页的记录列表 private int allRow; //...

    日期操作类 java

    // 格式:年-月-日 小时:分钟:秒 public static final String FORMAT_ONE = ... private static final SimpleDateFormat timeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); public DateUtil() {

    pageDate封装参数,不用实体类

    private static final long serialVersionUID = 1L; Map map = null; HttpServletRequest request; public PageData(HttpServletRequest request){ this.request = request; Map properties = request....

    Java五指棋

    private JMenuItem[] menuitem1={new JMenuItem("重新开始"),new JMenuItem("悔棋"),new JMenuItem("退出")}; private JMenuItem[] menuitem2={new JMenuItem("禁手选择"),new JMenuItem("人机博弈"),new ...

    带注释的Bootstrap.java

    private static final Log log = LogFactory.getLog(Bootstrap.class); /** * Daemon object used by main. */ private static Bootstrap daemon = null; private static final File catalinaBaseFile; ...

    旅店管理系统界面-手工书写

    private static final long serialVersionUID = 6261021704484837560L; private JPopupMenu popMenu; private ButtonGroup bg; private JRadioButton SetDark;// 置为脏房,待打扫 private JRadioButton ...

    @SuppressWarnings简介

    :java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一。可以标注在类、字段、方法、参数、构造方法,以及局部变量上。

    Java 电子邮件发送

    private static Log logger = LogFactory.getLog(EmailUtil.class); /** * 发动邮件的邮件服务器 */ // private static String host = "smtp.exmail.qq.com"; private static String host = "smtp.163.com"...

    ym_java-YOYOPlayer-src

    // public static final int PAUSED = 1; // public static final int STOPPED = 2; // public static final int OPENED = 3; // public static final int SEEKING = 4; private int m_status = UNKNOWN; private ...

    java写字板字体文件类源代码

    @SuppressWarnings("static-access") public FontFrame(MyNotepad myNotepad){ @SuppressWarnings("unused") int i = this.showConfirmDialog(myNotepad, createJPanel(), "字体", JOptionPane.OK_CANCEL_...

    jsp图书馆管理系统毕业设计

    public void delete(Long id); @SuppressWarnings("unchecked") public List getBookcase(); public Bookcase getBookcaseById(Long id); public boolean validateByName(String name); public int ...

    Java自定义异常案例--ExceptionManager(java源码)

    private static final long serialVersionUID = -6963187366089365790L; /** * This field <code>alerter</code> is used to show the information the Class offered. * * @see javax.swing.JOptionPane ...

    2012RobocupRuscue东大代码

    private static final String SPEAK_COMMUNICATION_MODEL = "kernel.standard.ChannelCommunicationModel"; protected static final String START_TIME_KEY = "kernel.agents.ignoreuntil"; private static final...

Global site tag (gtag.js) - Google Analytics