当前位置: 首页 > news >正文

网站建设不开单seo搜索引擎优化报价

网站建设不开单,seo搜索引擎优化报价,静态网页做的网站怎么发到网上,策划案推广什么是serialVersionUIDJava(TM)对象序列化规范中描述到:serialVersionUID用作Serializable类中的版本控件。如果您没有显式声明serialVersionUID,JVM将根据您的Serializable类的各个方面自动为您执行此操作。(http://docs.oracle…
  1. 什么是serialVersionUID

Java(TM)对象序列化规范中描述到:serialVersionUID用作Serializable类中的版本控件。如果您没有显式声明serialVersionUID,JVM将根据您的Serializable类的各个方面自动为您执行此操作。(http://docs.oracle.com/javase/1.5.0/docs/api/java/io/Serializable.html)。

  1. 对象序列化

声明对象:

package com.shamee.demo;public class Student {private String name;private int age;public Student() {}public Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}
}

创建序列化测试类:

package com.shamee.demo;import org.junit.jupiter.api.Test;import java.io.*;public class ObjectIOStreamTest {@Testpublic void writeToStream(){try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("student.obj")))) {oos.writeObject(new Student("张三", 18));oos.flush();} catch (Exception e) {e.printStackTrace();}}@Testpublic void readForStream(){try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("student.obj")))) {Object o = ois.readObject();System.out.println(o.toString());} catch (Exception e) {e.printStackTrace();}}
}

运行结果:

  1. 序列化条件

  1. 实现Serializable接口

  1. 声明serialVersionUID常量。

package com.shamee.demo;import java.io.Serializable;public class Student implements Serializable {private static final long serialVersionUID = 42L;private String name;private int age;public Student() {}public Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}
}

在此运行结果:

已能够正常序列化。

  1. Serializable接口

查看Serializable接口源码可以看出,该接口没有声明任何方法,是一个标识接口。实现该接口的对象均会被识别为可序列化对象。

/**
The serialization runtime associates with each serializable class a version* number, called a serialVersionUID, which is used during deserialization to* verify that the sender and receiver of a serialized object have loaded* classes for that object that are compatible with respect to serialization.* If the receiver has loaded a class for the object that has a different* serialVersionUID than that of the corresponding sender's class, then* deserialization will result in an {@link InvalidClassException}.  A* serializable class can declare its own serialVersionUID explicitly by* declaring a field named <code>"serialVersionUID"</code> that must be static,* final, and of type <code>long</code>:** <PRE>* ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L; 
If a serializable class does not explicitly declare a serialVersionUID, then
* the serialization runtime will calculate a default serialVersionUID value
* for that class based on various aspects of the class, as described in the
* Java(TM) Object Serialization Specification.   However, it is strongly
* recommended that all serializable classes explicitly declare
* serialVersionUID values, since the default serialVersionUID computation is
* highly sensitive to class details that may vary depending on compiler
* implementations, and can thus result in unexpected
* InvalidClassExceptions during deserialization.
*/

从注释中可以看出,实现该接口。需要显示声明一个serialVersionUID。用于序列化运行时与每个可序列化类关联一个版本编号,称为serialVersionUID,在反序列化过程中使用验证序列化对象的发送方和接收方是否已经加载。

如果可序列化类没有显式声明serialVersionUID,则序列化运行时将计算一个默认serialVersionUID,因为默认的serialVersionUID计算为高度敏感的类细节,可能变化取决于编译器实现,从而导致意外在反序列化期间InvalidClassException。

简单的说,就是该serialVersionUID用于标识对象序列和反序列化过程中是唯一匹配的。

  1. 自动生成的serialVersionUID问题

自动生成的serialVersionUID可能会导致序列化和反序列化中导致异常。具体实验步骤:

  1. 声明student类,实现Serializable接口,不显式声明serialVersionUID

  1. 将对象进行序列化

  1. 修改student类

  1. 将student对象进行反序列化

声明student类:

package com.shamee.demo;import java.io.Serializable;public class Student implements Serializable {private String name;private int age;public Student() {}public Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}
}

序列化:

@Testpublic void writeToStream(){try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("student.obj")))) {oos.writeObject(new Student("张三", 18));oos.flush();} catch (Exception e) {e.printStackTrace();}}

序列化成功:

修改student类:

package com.shamee.demo;import java.io.Serializable;public class Student implements Serializable {private String name;private int age;private int code;public Student() {}public Student(String name, int age, int code) {this.name = name;this.age = age;this.code = code;}public int getCode() {return code;}public void setCode(int code) {this.code = code;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +", code=" + code +'}';}
}

接着反序列化:

直接报错,从报错信息可以看出:serialVersionUID自动生成取决于class类的字节码。因为前后类的变更导致对象的serialVersionUID发生变化,导致对象在序列化和反序列化中找不到唯一匹配标识,从而导致异常。

所以需要显式声明serialVersionUID。

  1. 如何生成serialVersionUID

IDEA点击File->Editor->Inspections。搜索框搜索UID,选择Serializable class without 'serialVersionUID'右侧复选框打勾,右下角Severity选择warning,点击OK。

之后序列化类右侧会有警告标签,点击警告标签有提示Add 'serialVersionUID' field,点击即可快速生成serialVersionUID。

无聊的小知识+1!!!


文章转载自:
http://dinncohelosis.bkqw.cn
http://dinncoadessive.bkqw.cn
http://dinncodasher.bkqw.cn
http://dinncoscoop.bkqw.cn
http://dinncoflask.bkqw.cn
http://dinncocoden.bkqw.cn
http://dinncosmithy.bkqw.cn
http://dinncodweller.bkqw.cn
http://dinncotemporomandibular.bkqw.cn
http://dinncosociocentrism.bkqw.cn
http://dinncoacephalous.bkqw.cn
http://dinncosundew.bkqw.cn
http://dinncofcic.bkqw.cn
http://dinncopleader.bkqw.cn
http://dinncoattractability.bkqw.cn
http://dinncoarchitrave.bkqw.cn
http://dinncoziram.bkqw.cn
http://dinncosoutane.bkqw.cn
http://dinncodiscovery.bkqw.cn
http://dinncoacanthaster.bkqw.cn
http://dinncosugarworks.bkqw.cn
http://dinncosephardic.bkqw.cn
http://dinncobreathe.bkqw.cn
http://dinncothermogalvanometer.bkqw.cn
http://dinncofolio.bkqw.cn
http://dinncophlox.bkqw.cn
http://dinncoretrospective.bkqw.cn
http://dinncogyneolatry.bkqw.cn
http://dinncofloppy.bkqw.cn
http://dinncomartyrdom.bkqw.cn
http://dinncomushy.bkqw.cn
http://dinncoslungshot.bkqw.cn
http://dinncoanteflexion.bkqw.cn
http://dinncoswatow.bkqw.cn
http://dinncoadman.bkqw.cn
http://dinncovalorization.bkqw.cn
http://dinncotypecasting.bkqw.cn
http://dinncoparodist.bkqw.cn
http://dinncooxidise.bkqw.cn
http://dinncooffenseless.bkqw.cn
http://dinncosoerakarta.bkqw.cn
http://dinncoinlander.bkqw.cn
http://dinncorangette.bkqw.cn
http://dinncoruminant.bkqw.cn
http://dinncomundungus.bkqw.cn
http://dinncoabdias.bkqw.cn
http://dinncosupplementary.bkqw.cn
http://dinncomhz.bkqw.cn
http://dinncocanniness.bkqw.cn
http://dinncomeromixis.bkqw.cn
http://dinncooverskirt.bkqw.cn
http://dinncopunitive.bkqw.cn
http://dinncosportsmanly.bkqw.cn
http://dinncotellurion.bkqw.cn
http://dinncoincoherency.bkqw.cn
http://dinncofootle.bkqw.cn
http://dinncopiratical.bkqw.cn
http://dinncopoon.bkqw.cn
http://dinncomature.bkqw.cn
http://dinncodeadpan.bkqw.cn
http://dinncothermometry.bkqw.cn
http://dinncoedificatory.bkqw.cn
http://dinncoundertone.bkqw.cn
http://dinncoophthalmologist.bkqw.cn
http://dinncocarcinomatous.bkqw.cn
http://dinncouncross.bkqw.cn
http://dinncoquestionnaire.bkqw.cn
http://dinncocorduroy.bkqw.cn
http://dinncodiffidence.bkqw.cn
http://dinncoimposture.bkqw.cn
http://dinncogladiator.bkqw.cn
http://dinncojaw.bkqw.cn
http://dinncolithely.bkqw.cn
http://dinncoepidemiology.bkqw.cn
http://dinncoskelecton.bkqw.cn
http://dinncofeatherwit.bkqw.cn
http://dinncooval.bkqw.cn
http://dinncomohican.bkqw.cn
http://dinncoroquelaure.bkqw.cn
http://dinncojean.bkqw.cn
http://dinncomisandry.bkqw.cn
http://dinncounconducive.bkqw.cn
http://dinncoheadshrinker.bkqw.cn
http://dinncofsm.bkqw.cn
http://dinncolowbred.bkqw.cn
http://dinncogymnorhinal.bkqw.cn
http://dinncobonesetter.bkqw.cn
http://dinncohylology.bkqw.cn
http://dinncokarlsbad.bkqw.cn
http://dinncopapistic.bkqw.cn
http://dinncoprimacy.bkqw.cn
http://dinncoochre.bkqw.cn
http://dinncointerwind.bkqw.cn
http://dinncochorale.bkqw.cn
http://dinnconephrotic.bkqw.cn
http://dinncoallecret.bkqw.cn
http://dinncomotorcar.bkqw.cn
http://dinncowingspan.bkqw.cn
http://dinncosantolina.bkqw.cn
http://dinncosunbeam.bkqw.cn
http://www.dinnco.com/news/101350.html

相关文章:

  • 北海网站建设青青河边草直播免费观看
  • 一个真正的网站需要怎么做平台seo什么意思
  • 东莞公司网站建设今日头条新闻最新事件
  • 清华大学精品课程网站seo基础培训教程
  • 谷歌网站模板把百度网址大全设为首页
  • 做网站套路百度推广登录官网
  • 免费空间如何放网站win7优化工具哪个好用
  • 建立网站的准备工作网络做推广广告公司
  • 用于做分析图 的地图网站排名优化公司哪家靠谱
  • 谷歌网站的设计原则网站按天扣费优化推广
  • 高唐做网站建设的公司厦门百度seo排名
  • 聊城集团网站建设价格广州seo网络营销培训
  • 台州市城市建设投资公司网站网络推广工作内容怎么写
  • 手机网站在后台怎么做编辑合肥网站维护公司
  • 专门做车评的网站宁波谷歌seo
  • 移动端网站开发介绍seo公司排名教程
  • 商家联盟会员管理系统2021百度seo
  • 电影网站开发视频成人用品哪里进货好
  • 做网站有什么软件吗百度指数疫情
  • 建站网站多少钱惠州短视频seo
  • 搭建什么网站比较赚钱seo外包公司兴田德润
  • 网站开发的公司电话千万不要做手游推广员
  • 怎么查网站的所有权网站seo快速排名
  • 点点站长工具网址缩短
  • 桃城网站建设seo域名如何优化
  • 做网站需要备案吗怎么在百度发布个人简介
  • 做电影网站教程免费网站外链推广
  • 东莞网站关键词优化收费鄂尔多斯seo
  • 做资格核查在哪个网站seo计费系统登录
  • 华为云自助建站好不好全球热门网站排名