{"id":8976,"date":"2022-12-02T21:45:28","date_gmt":"2022-12-02T13:45:28","guid":{"rendered":"http:\/\/123.57.164.21\/?p=8976"},"modified":"2022-12-02T21:56:50","modified_gmt":"2022-12-02T13:56:50","slug":"java%e5%ba%8f%e5%88%97%e5%8c%96","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=8976","title":{"rendered":"Java\u5e8f\u5217\u5316"},"content":{"rendered":"\n<p><strong>\u5e8f\u5217\u5316\u7684\u542b\u4e49<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5e8f\u5217\u5316\u7684\u539f\u672c\u610f\u56fe\u662f\u5e0c\u671b\u5bf9\u4e00\u4e2aJava\u5bf9\u8c61\u4f5c\u4e00\u4e0b\u201c\u53d8\u6362\u201d\uff0c\u53d8\u6210\u5b57\u8282\u5e8f\u5217\uff0c\u8fd9\u6837\u4e00\u6765\u65b9\u4fbf\u6301\u4e45\u5316\u5b58\u50a8\u5230\u78c1\u76d8\uff0c\u907f\u514d\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\u540e\u5bf9\u8c61\u5c31\u4ece\u5185\u5b58\u91cc\u6d88\u5931\uff0c\u53e6\u5916\u53d8\u6362\u6210\u5b57\u8282\u5e8f\u5217\u4e5f\u66f4\u4fbf\u4e8e\u7f51\u7edc\u8fd0\u8f93\u548c\u4f20\u64ad\uff0c\u6240\u4ee5\u6982\u5ff5\u4e0a\u5f88\u597d\u7406\u89e3\uff1a<\/p>\n\n\n\n<ul><li><strong>\u5e8f\u5217\u5316<\/strong>\uff1a\u628aJava\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u8282\u5e8f\u5217\u3002<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42-1024x223.png\" alt=\"\" class=\"wp-image-8988\" width=\"502\" height=\"108\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42-1024x223.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42-300x65.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42-768x167.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42-830x181.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42-230x50.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42-350x76.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-42.png 1340w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/figure><\/div>\n\n\n\n<ul><li><strong>\u53cd\u5e8f\u5217\u5316<\/strong>\uff1a\u628a\u5b57\u8282\u5e8f\u5217\u6062\u590d\u4e3a\u539f\u5148\u7684Java\u5bf9\u8c61\u3002<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-1024x204.png\" alt=\"\" class=\"wp-image-8989\" width=\"474\" height=\"94\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-1024x204.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-300x60.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-768x153.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-830x166.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-230x46.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-350x70.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43-480x96.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-43.png 1434w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/figure><\/div>\n\n\n\n<p>\u800c\u4e14\u5e8f\u5217\u5316\u673a\u5236\u4ece\u67d0\u79cd\u610f\u4e49\u4e0a\u6765\u8bf4\u4e5f\u5f25\u8865\u4e86\u5e73\u53f0\u5316\u7684\u4e00\u4e9b\u5dee\u5f02\uff0c\u6bd5\u7adf\u8f6c\u6362\u540e\u7684\u5b57\u8282\u6d41\u53ef\u4ee5\u5728\u5176\u4ed6\u5e73\u53f0\u4e0a\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u6765\u6062\u590d\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\u7b80\u5355\u8bf4\u5c31\u662f\u4e3a\u4e86\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\u7684\u5404\u79cd\u5bf9\u8c61\u7684\u72b6\u6001\uff0c\u5e76\u4e14\u53ef\u4ee5\u628a\u4fdd\u5b58\u7684\u5bf9\u8c61\u72b6\u6001\u518d\u8bfb\u51fa\u6765\u3002\u867d\u7136\u4f60\u53ef\u4ee5\u7528\u4f60\u81ea\u5df1\u7684\u5404\u79cd\u5404\u6837\u7684\u65b9\u6cd5\u6765\u4fdd\u5b58Object States\uff0c\u4f46\u662fJava\u7ed9\u4f60\u63d0\u4f9b\u4e00\u79cd\u5e94\u8be5\u6bd4\u4f60\u81ea\u5df1\u597d\u7684\u4fdd\u5b58\u5bf9\u8c61\u72b6\u6001\u7684\u673a\u5236,\u90a3\u5c31\u662f\u5e8f\u5217\u5316\u3002<\/p>\n\n\n\n<p>\u603b\u7ed3\u6765\u8bf4\uff0c<strong>\u5e8f\u5217\u5316\u5c31\u662f\u5c06\u5bf9\u8c61\u8f6c\u6362\u6210\u4e8c\u8fdb\u5236\u6570\u636e\u7684\u8fc7\u7a0b\uff0c\u4ee5\u65b9\u4fbf\u4f20\u8f93\u6216\u5b58\u50a8\u3002\u800c\u53cd\u5e8f\u5217\u5c31\u662f\u5c06\u4e8c\u8fdb\u5236\u8f6c\u6362\u4e3a\u5bf9\u8c61\u7684\u8fc7\u7a0b\u3002<\/strong><\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u60c5\u51b5\u4e0b\u9700\u8981\u5e8f\u5217\u5316<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<ul><li>\u5f53\u4f60\u60f3\u628a\u7684\u5185\u5b58\u4e2d\u7684\u5bf9\u8c61\u4fdd\u5b58\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\u6216\u8005\u6570\u636e\u5e93\u4e2d\u65f6\u5019\uff1b<\/li><li>\u5f53\u4f60\u60f3\u7528\u5e8f\u5217\u5316\u5728\u7f51\u7edc\u4e0a\u4f20\u9001\u5bf9\u8c61\u7684\u65f6\u5019\uff1b<\/li><li>\u5f53\u4f60\u60f3\u901a\u8fc7RMI\u4f20\u8f93\u5bf9\u8c61\u7684\u65f6\u5019\uff1b<\/li><\/ul>\n\n\n\n<p><strong>\u5982\u4f55\u5e8f\u5217\u5316<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5728\u4ecb\u7ecd\u5bf9\u8c61\u5e8f\u5217\u5316\u7684\u4f7f\u7528\u65b9\u6cd5\u4e4b\u524d\uff0c\u5148\u770b\u770b\u6211\u4eec\u4e4b\u524d\u662f\u600e\u4e48\u5b58\u50a8\u4e00\u4e2a\u5bf9\u8c61\u7c7b\u578b\u7684\u6570\u636e\u7684\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u7b80\u5355\u5b9a\u4e49\u4e00\u4e2aStudent\u7c7b\npublic class Student {\n \n     private String name;\n     private int age;\n \n     public Student(){}\n     public Student(String name,int age){\n         this.name = name;\n         this.age=age;\n     }\n \n     public void setName(String name){\n         this.name = name;\n     }\n     public void setAge(int age){\n         this.age = age;\n     }\n     public String getName(){\n         return this.name;\n     }\n     public int getAge(){\n         return this.age;\n     }\n     \/\/\u91cd\u5199toString\n     @Override\n     public String toString(){\n         return (\"my name is:\"+this.name+\" age is:\"+this.age);\n     }\n}\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/main\u65b9\u6cd5\u5b9e\u73b0\u4e86\u5c06\u5bf9\u8c61\u5199\u5165\u6587\u4ef6\u5e76\u8bfb\u53d6\u51fa\u6765\npublic static void main(String[] args) throws IOException{\n \n     DataOutputStream dot = new DataOutputStream(new FileOutputStream(\"hello.txt\"));\n     Student stuW = new Student(\"walker\",21);\n     \/\/\u5c06\u6b64\u5bf9\u8c61\u5199\u5165\u5230\u6587\u4ef6\u4e2d\n     dot.writeUTF(stuW.getName());\n     dot.writeInt(stuW.getAge());\n     dot.close();\n \n \/\/\u5c06\u5bf9\u8c61\u4ece\u6587\u4ef6\u4e2d\u8bfb\u51fa\n DataInputStream din = new DataInputStream(new FileInputStream(\"hello.txt\"));\n     Student stuR = new Student();\n     stuR.setName(din.readUTF());\n     stuR.setAge(din.readInt());\n     din.close();\n \n     System.out.println(stuR);\n }<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u8f93\u51fa\u7ed3\u679c\uff1amy name is:walker age is:21<\/pre>\n\n\n\n<p>\u663e\u7136\u8fd9\u79cd\u4ee3\u7801\u4e66\u5199\u662f\u7e41\u7410\u7684\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u770b\u770b\uff0c\u5982\u4f55\u4f7f\u7528\u5e8f\u5217\u5316\u6765\u5b8c\u6210\u4fdd\u5b58\u5bf9\u8c61\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void main(String[] args) throws IOException, ClassNotFoundException {\n \n     ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(\"hello.txt\"));\n     Student stuW = new Student(\"walker\",21);\n     oos.writeObject(stuW);\n     oos.close();\n \n     \/\/\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u8be5\u5bf9\u8c61\u8fd4\u56de\n     ObjectInputStream ois = new ObjectInputStream(new FileInputStream(\"hello.txt\"));\n     Student stuR = (Student)ois.readObject();\n     System.out.println(stuR);\n }\n <\/pre>\n\n\n\n<p>\u5199\u5165\u6587\u4ef6\u65f6\uff0c\u53ea\u7528\u4e86\u4e00\u6761\u8bed\u53e5\u5c31\u662fwriteObject\uff0c\u8bfb\u53d6\u65f6\u4e5f\u662f\u53ea\u7528\u4e86\u4e00\u6761\u8bed\u53e5readObject\u3002\u5e76\u4e14Student\u4e2d\u7684\u90a3\u4e9bset\uff0cget\u65b9\u6cd5\u90fd\u7528\u4e0d\u5230\u4e86\u3002\u662f\u4e0d\u662f\u5f88\u7b80\u6d01\u5462\uff1f\u63a5\u4e0b\u6765\u4ecb\u7ecd\u5b9e\u73b0\u7ec6\u8282\u3002<\/p>\n\n\n\n<p><strong>Serializable\u6f14\u793a<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u7136\u800cJava\u76ee\u524d\u5e76\u6ca1\u6709\u4e00\u4e2a\u5173\u952e\u5b57\u53ef\u4ee5\u76f4\u63a5\u53bb\u5b9a\u4e49\u4e00\u4e2a\u6240\u8c13\u7684\u201c\u53ef\u6301\u4e45\u5316\u201d\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\u5bf9\u8c61\u7684\u6301\u4e45\u5316\u548c\u53cd\u6301\u4e45\u5316\u9700\u8981\u9760\u7a0b\u5e8f\u5458\u5728\u4ee3\u7801\u91cc\u624b\u52a8<strong>\u663e\u5f0f\u5730<\/strong>\u8fdb\u884c\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u8fd8\u539f\u7684\u52a8\u4f5c\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u5982\u6211\u4eec\u8981\u5bf9<a rel=\"noreferrer noopener\" href=\"https:\/\/www.zhihu.com\/search?q=Student%E7%B1%BB%E5%AF%B9%E8%B1%A1&amp;search_source=Entity&amp;hybrid_search_source=Entity&amp;hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A1898221893%7D\" target=\"_blank\">Student\u7c7b\u5bf9\u8c61<\/a>\u5e8f\u5217\u5316\u5230\u4e00\u4e2a\u540d\u4e3astudent.txt\u7684\u6587\u672c\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u518d\u901a\u8fc7\u6587\u672c\u6587\u4ef6\u53cd\u5e8f\u5217\u5316\u6210Student\u7c7b\u5bf9\u8c61\uff1a<\/p>\n\n\n\n<p>1\u3001Student\u7c7b\u5b9a\u4e49<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class Student implements Serializable {\n\n    private String name;\n    private Integer age;\n    private Integer score;\n \n    @Override\n    public String toString() {\n        return \"Student:\" + '\\n' +\n        \"name = \" + this.name + '\\n' +\n        \"age = \" + this.age + '\\n' +\n        \"score = \" + this.score + '\\n'\n        ;\n    }\n \n    \/\/ ... \u5176\u4ed6\u7701\u7565 ...\n}\n<\/pre>\n\n\n\n<p>2\u3001\u5e8f\u5217\u5316<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void serialize(  ) throws IOException {\n\n    Student student = new Student();\n    student.setName(\"CodeSheep\");\n    student.setAge( 18 );\n    student.setScore( 1000 );\n\n    ObjectOutputStream objectOutputStream = \n        new ObjectOutputStream( new FileOutputStream( new File(\"student.txt\") ) );\n    objectOutputStream.writeObject( student );\n    objectOutputStream.close();\n \n    System.out.println(\"\u5e8f\u5217\u5316\u6210\u529f\uff01\u5df2\u7ecf\u751f\u6210student.txt\u6587\u4ef6\");\n    System.out.println(\"==============================================\");\n}<\/pre>\n\n\n\n<p>3\u3001\u53cd\u5e8f\u5217\u5316<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void deserialize(  ) throws IOException, ClassNotFoundException {\n    ObjectInputStream objectInputStream = \n        new ObjectInputStream( new FileInputStream( new File(\"student.txt\") ) );\n    Student student = (Student) objectInputStream.readObject();\n    objectInputStream.close();\n \n    System.out.println(\"\u53cd\u5e8f\u5217\u5316\u7ed3\u679c\u4e3a\uff1a\");\n    System.out.println( student );\n}\n<\/pre>\n\n\n\n<p>4\u3001\u8fd0\u884c\u7ed3\u679c<\/p>\n\n\n\n<p>\u63a7\u5236\u53f0\u6253\u5370\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u5e8f\u5217\u5316\u6210\u529f\uff01\u5df2\u7ecf\u751f\u6210student.txt\u6587\u4ef6\n==============================================\n\u53cd\u5e8f\u5217\u5316\u7ed3\u679c\u4e3a\uff1a\nStudent:\nname = CodeSheep\nage = 18\nscore = 1000<\/pre>\n\n\n\n<p><strong>Serializable\u63a5\u53e3\u6709\u4f55\u7528\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4e0a\u9762\u5728\u5b9a\u4e49Student\u7c7b\u65f6\uff0c\u5b9e\u73b0\u4e86\u4e00\u4e2aSerializable\u63a5\u53e3\uff0c\u7136\u800c\u5f53\u6211\u4eec\u70b9\u8fdbSerializable\u63a5\u53e3\u5185\u90e8\u67e5\u770b\uff0c\u53d1\u73b0\u5b83\u7adf\u7136\u662f\u4e00\u4e2a\u7a7a\u63a5\u53e3\uff0c\u5e76\u6ca1\u6709\u5305\u542b\u4efb\u4f55\u65b9\u6cd5\uff01<\/p>\n\n\n\n<p>\u8bd5\u60f3\uff0c\u5982\u679c\u4e0a\u9762\u5728\u5b9a\u4e49Student\u7c7b\u65f6\u5fd8\u4e86\u52a0implements Serializable\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u5462\uff1f<\/p>\n\n\n\n<p>\u5b9e\u9a8c\u7ed3\u679c\u662f\uff1a\u6b64\u65f6\u7684\u7a0b\u5e8f\u8fd0\u884c\u4f1a\u62a5\u9519\uff0c\u5e76\u629b\u51faNotSerializableException\u5f02\u5e38\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-1024x284.png\" alt=\"\" class=\"wp-image-8980\" width=\"533\" height=\"147\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-1024x284.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-300x83.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-768x213.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-830x230.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-230x64.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-350x97.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39-480x133.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-39.png 1394w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u6309\u7167\u9519\u8bef\u63d0\u793a\uff0c\u7531\u6e90\u7801\u4e00\u76f4\u8ddf\u5230ObjectOutputStream\u7684writeObject0()\u65b9\u6cd5\u5e95\u5c42\u4e00\u770b\uff0c\u624d\u604d\u7136\u5927\u609f\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-1024x853.png\" alt=\"\" class=\"wp-image-8981\" width=\"560\" height=\"466\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-1024x853.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-300x250.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-768x640.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-830x691.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-230x192.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-350x292.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40-480x400.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-40.png 1318w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/figure><\/div>\n\n\n\n<p>\u5982\u679c\u4e00\u4e2a\u5bf9\u8c61\u65e2\u4e0d\u662f\u5b57\u7b26\u4e32\u3001\u6570\u7ec4\u3001\u679a\u4e3e\uff0c\u800c\u4e14\u4e5f\u6ca1\u6709\u5b9e\u73b0Serializable\u63a5\u53e3\u7684\u8bdd\uff0c\u5728\u5e8f\u5217\u5316\u65f6\u5c31\u4f1a\u629b\u51faNotSerializableException\u5f02\u5e38\uff01<\/p>\n\n\n\n<p>\u539f\u6765Serializable\u63a5\u53e3\u4e5f\u4ec5\u4ec5\u53ea\u662f\u505a\u4e00\u4e2a\u6807\u8bb0\u7528\uff01\uff01\uff01\u5b83\u544a\u8bc9\u4ee3\u7801\u53ea\u8981\u662f\u5b9e\u73b0\u4e86Serializable\u63a5\u53e3\u7684\u7c7b\u90fd\u662f\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u7684\uff01\u7136\u800c\u771f\u6b63\u7684\u5e8f\u5217\u5316\u52a8\u4f5c\u4e0d\u9700\u8981\u9760\u5b83\u5b8c\u6210\u3002<\/p>\n\n\n\n<p><strong>serialVersionUID\u53f7\u6709\u4f55\u7528\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u76f8\u4fe1\u4f60\u4e00\u5b9a\u7ecf\u5e38\u770b\u5230\u6709\u4e9b\u7c7b\u4e2d\u5b9a\u4e49\u4e86\u5982\u4e0b\u4ee3\u7801\u884c\uff0c\u5373\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3aserialVersionUID\u7684\u5b57\u6bb5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">private static final long serialVersionUID = -4392658638228508589L;<\/pre>\n\n\n\n<p>\u4f60\u77e5\u9053\u8fd9\u53e5\u58f0\u660e\u7684\u542b\u4e49\u5417\uff1f\u4e3a\u4ec0\u4e48\u8981\u641e\u4e00\u4e2a\u540d\u4e3aserialVersionUID\u7684\u5e8f\u5217\u53f7\uff1f<\/p>\n\n\n\n<p>\u7ee7\u7eed\u6765\u505a\u4e00\u4e2a\u7b80\u5355\u5b9e\u9a8c\uff0c\u8fd8\u62ff\u4e0a\u9762\u7684Student\u7c7b\u4e3a\u4f8b\uff0c\u6211\u4eec\u5e76\u6ca1\u6709\u4eba\u4e3a\u5728\u91cc\u9762\u663e\u5f0f\u5730\u58f0\u660e\u4e00\u4e2aserialVersionUID\u5b57\u6bb5\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u9996\u5148\u8fd8\u662f\u8c03\u7528\u4e0a\u9762\u7684serialize()\u65b9\u6cd5\uff0c\u5c06\u4e00\u4e2aStudent\u5bf9\u8c61\u5e8f\u5217\u5316\u5230\u672c\u5730\u78c1\u76d8\u4e0a\u7684student.txt\u6587\u4ef6\uff1a<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5728Student\u7c7b\u91cc\u9762\u52a8\u70b9\u624b\u811a\uff0c\u6bd4\u5982\u5728\u91cc\u9762\u518d\u589e\u52a0\u4e00\u4e2a\u540d\u4e3aid\u7684\u5b57\u6bb5\uff0c\u8868\u793a\u5b66\u751f\u5b66\u53f7\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class Student implements Serializable {\n    private String name;\n    private Integer age;\n    private Integer score;\n    private Integer id;\n\n<\/pre>\n\n\n\n<p>\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u62ff\u521a\u624d\u5df2\u7ecf\u5e8f\u5217\u5316\u5230\u672c\u5730\u7684student.txt\u6587\u4ef6\uff0c\u8fd8\u7528\u5982\u4e0b\u4ee3\u7801\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\uff0c\u8bd5\u56fe\u8fd8\u539f\u51fa\u521a\u624d\u90a3\u4e2aStudent\u5bf9\u8c61\uff1a<\/p>\n\n\n\n<p>\u8fd0\u884c\u53d1\u73b0\u62a5\u9519\u4e86\uff0c\u5e76\u4e14\u629b\u51fa\u4e86InvalidClassException\u5f02\u5e38<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"127\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-1024x127.png\" alt=\"\" class=\"wp-image-8983\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-1024x127.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-300x37.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-768x96.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-830x103.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-230x29.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-350x44.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r-480x60.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/v2-454c57439419d012a2b651046e662ac9_r.png 1526w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u5730\u65b9\u63d0\u793a\u7684\u4fe1\u606f\u975e\u5e38\u660e\u786e\u4e86\uff1a\u5e8f\u5217\u5316\u524d\u540e\u7684serialVersionUID\u53f7\u7801\u4e0d\u517c\u5bb9\uff01<\/p>\n\n\n\n<p>\u4ece\u8fd9\u5730\u65b9\u6700\u8d77\u7801\u53ef\u4ee5\u5f97\u51fa\u4e24\u4e2a\u91cd\u8981\u4fe1\u606f\uff1a<\/p>\n\n\n\n<ul><li>1\u3001serialVersionUID\u662f\u5e8f\u5217\u5316\u524d\u540e\u7684\u552f\u4e00\u6807\u8bc6\u7b26<\/li><li>2\u3001\u9ed8\u8ba4\u5982\u679c\u6ca1\u6709\u4eba\u4e3a\u663e\u5f0f\u5b9a\u4e49\u8fc7serialVersionUID\uff0c\u90a3\u7f16\u8bd1\u5668\u4f1a\u4e3a\u5b83\u81ea\u52a8\u58f0\u660e\u4e00\u4e2a\uff01<\/li><\/ul>\n\n\n\n<p>\u7b2c1\u4e2a\u95ee\u9898\uff1a serialVersionUID\u5e8f\u5217\u5316ID\uff0c\u53ef\u4ee5\u770b\u6210\u662f\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u8fc7\u7a0b\u4e2d\u7684\u201c\u6697\u53f7\u201d\uff0c\u5728\u53cd\u5e8f\u5217\u5316\u65f6\uff0cJVM\u4f1a\u628a\u5b57\u8282\u6d41\u4e2d\u7684\u5e8f\u5217\u53f7ID\u548c\u88ab\u5e8f\u5217\u5316\u7c7b\u4e2d\u7684\u5e8f\u5217\u53f7ID\u505a\u6bd4\u5bf9\uff0c\u53ea\u6709\u4e24\u8005\u4e00\u81f4\uff0c\u624d\u80fd\u91cd\u65b0\u53cd\u5e8f\u5217\u5316\uff0c\u5426\u5219\u5c31\u4f1a\u62a5\u5f02\u5e38\u6765\u7ec8\u6b62\u53cd\u5e8f\u5217\u5316\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p>\u7b2c2\u4e2a\u95ee\u9898\uff1a \u5982\u679c\u5728\u5b9a\u4e49\u4e00\u4e2a\u53ef\u5e8f\u5217\u5316\u7684\u7c7b\u65f6\uff0c\u6ca1\u6709\u4eba\u4e3a\u663e\u5f0f\u5730\u7ed9\u5b83\u5b9a\u4e49\u4e00\u4e2aserialVersionUID\u7684\u8bdd\uff0c\u5219Java\u8fd0\u884c\u65f6\u73af\u5883\u4f1a\u6839\u636e\u8be5\u7c7b\u7684\u5404\u65b9\u9762\u4fe1\u606f\u81ea\u52a8\u5730\u4e3a\u5b83\u751f\u6210\u4e00\u4e2a\u9ed8\u8ba4\u7684serialVersionUID\uff0c\u4e00\u65e6\u50cf\u4e0a\u9762\u4e00\u6837\u66f4\u6539\u4e86\u7c7b\u7684\u7ed3\u6784\u6216\u8005\u4fe1\u606f\uff0c\u5219\u7c7b\u7684serialVersionUID\u4e5f\u4f1a\u8ddf\u7740\u53d8\u5316\uff01<\/p>\n\n\n\n<p>\u6240\u4ee5\uff0c\u4e3a\u4e86serialVersionUID\u7684\u786e\u5b9a\u6027\uff0c\u5199\u4ee3\u7801\u65f6\u8fd8\u662f\u5efa\u8bae\uff0c\u51e1\u662fimplements Serializable\u7684\u7c7b\uff0c\u90fd\u6700\u597d\u4eba\u4e3a\u663e\u5f0f\u5730\u4e3a\u5b83\u58f0\u660e\u4e00\u4e2aserialVersionUID<a href=\"https:\/\/www.zhihu.com\/search?q=%E6%98%8E%E7%A1%AE%E5%80%BC&amp;search_source=Entity&amp;hybrid_search_source=Entity&amp;hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A1898221893%7D\" target=\"_blank\" rel=\"noreferrer noopener\">\u660e\u786e\u503c<\/a><\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u5982\u679c\u4e0d\u60f3\u624b\u52a8\u8d4b\u503c\uff0c\u4f60\u4e5f\u53ef\u4ee5\u501f\u52a9IDE\u7684\u81ea\u52a8\u6dfb\u52a0\u529f\u80fd\uff0c\u6bd4\u5982\u6211\u4f7f\u7528\u7684IntelliJ IDEA\uff0c\u6309alt + enter\u5c31\u53ef\u4ee5\u4e3a\u7c7b\u81ea\u52a8\u751f\u6210\u548c\u6dfb\u52a0serialVersionUID\u5b57\u6bb5\uff0c\u5341\u5206\u65b9\u4fbf<\/p>\n\n\n\n<p><strong>\u4e24\u79cd\u7279\u6b8a\u60c5\u51b5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>1\u3001\u51e1\u662f\u88abstatic\u4fee\u9970\u7684\u5b57\u6bb5\u662f\u4e0d\u4f1a\u88ab\u5e8f\u5217\u5316\u7684<\/p>\n\n\n\n<p>2\u3001\u51e1\u662f\u88abtransient\u4fee\u9970\u7b26\u4fee\u9970\u7684\u5b57\u6bb5\u4e5f\u662f\u4e0d\u4f1a\u88ab\u5e8f\u5217\u5316\u7684<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u7b2c\u4e00\u70b9\uff0c\u56e0\u4e3a\u5e8f\u5217\u5316\u4fdd\u5b58\u7684\u662f\u5bf9\u8c61\u7684\u72b6\u6001\u800c\u975e\u7c7b\u7684\u72b6\u6001\uff0c\u6240\u4ee5\u4f1a\u5ffd\u7565static\u9759\u6001\u57df\u4e5f\u662f\u7406\u6240\u5e94\u5f53\u7684\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u7b2c\u4e8c\u70b9\uff0c\u5c31\u9700\u8981\u4e86\u89e3\u4e00\u4e0btransient\u4fee\u9970\u7b26\u7684\u4f5c\u7528\u4e86\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u5728\u5e8f\u5217\u5316\u67d0\u4e2a\u7c7b\u7684\u5bf9\u8c61\u65f6\uff0c\u5c31\u662f\u4e0d\u5e0c\u671b\u67d0\u4e2a\u5b57\u6bb5\u88ab\u5e8f\u5217\u5316\uff08\u6bd4\u5982\u8fd9\u4e2a\u5b57\u6bb5\u5b58\u653e\u7684\u662f\u9690\u79c1\u503c\uff0c\u5982\uff1a\u5bc6\u7801\u7b49\uff09\uff0c\u90a3\u8fd9\u65f6\u5c31\u53ef\u4ee5\u7528transient\u4fee\u9970\u7b26\u6765\u4fee\u9970\u8be5\u5b57\u6bb5\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\u5728\u4e4b\u524d\u5b9a\u4e49\u7684Student\u7c7b\u4e2d\uff0c\u52a0\u5165\u4e00\u4e2a\u5bc6\u7801\u5b57\u6bb5\uff0c\u4f46\u662f\u4e0d\u5e0c\u671b\u5e8f\u5217\u5316\u5230txt\u6587\u672c\uff0c\u5219\u53ef\u4ee5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class Student implements Serializable {\n    private static final long serialVersionUID = -4392658638228508589L;\n    private transient String name;\n    private Integer age;\n    private Integer score;\n    private transient String passwd;\n<\/pre>\n\n\n\n<p>\u8fd9\u6837\u5728\u5e8f\u5217\u5316Student\u7c7b\u5bf9\u8c61\u65f6\uff0cpassword\u5b57\u6bb5\u4f1a\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u503cnull\uff0c\u8fd9\u4e00\u70b9\u53ef\u4ee5\u4ece\u53cd\u5e8f\u5217\u5316\u6240\u5f97\u5230\u7684\u7ed3\u679c\u6765\u770b\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void serialize() throws IOException {\n\n    Student student = new Student();\n    student.setName(\"CodeSheep\");\n    student.setAge(18);\n    student.setScore(1000);\n    student.setPasswd(\"123\");\n<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-1024x305.png\" alt=\"\" class=\"wp-image-8984\" width=\"553\" height=\"164\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-1024x305.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-300x89.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-768x228.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-830x247.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-230x68.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-350x104.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41-480x143.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-41.png 1116w\" sizes=\"(max-width: 553px) 100vw, 553px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u4f55\u65f6\u9700\u8981\u5b9e\u73b0<a rel=\"noreferrer noopener\" href=\"https:\/\/so.csdn.net\/so\/search?q=Serializable&amp;spm=1001.2101.3001.7020\" target=\"_blank\">Serializable<\/a>\u63a5\u53e3\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Java\u4e2d\u6709\u4e00\u4e2a\u63a5\u53e3\u662fjava.io.Serializable\uff0c\u5b9e\u73b0\u8fd9\u4e2a\u63a5\u53e3\uff0c\u4e0d\u7528\u5b9e\u73b0\u4efb\u4f55\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u63a5\u53e3\u5c31\u662f\u4e00\u4e2a\u6807\u8bc6\u4f5c\u7528\uff0cjvm\u5728\u505a\u5e8f\u5217\u5316\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u4f1a\u53bb\u68c0\u67e5\u76ee\u6807\u7c7b\u6709\u6ca1\u6709\u5b9e\u73b0java.io.Serializable\u63a5\u53e3\uff0c\u6ca1\u6709\u5b9e\u73b0\u7684\u8bdd\uff0c\u6839\u636e\u60c5\u51b5\u629b\u51fa\u5f02\u5e38\uff1ajava.io.NotSerializableException\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u9700\u8981\u660e\u786e\u7684\u662f\u54ea\u4e9b\u64cd\u4f5c\u4f1a\u53bb\u68c0\u67e5\u662f\u5426\u5b9e\u73b0java.io.Serializable\u63a5\u53e3\uff0c\u4e00\u822c\u800c\u8a00\uff0c\u5728\u5c06\u5bf9\u8c61\u8f6c\u6362\u6210\u6d41\u65f6\uff0c\u4f1a\u53bb\u68c0\u67e5\u3002\u6bd4\u5982\u8f6c\u6362\u6210\u6d41\u8fdb\u884c\u7f51\u7edc\u4f20\u8f93\uff0c\u8f6c\u6362\u6210\u6d41\u6301\u4e45\u5316\u5230\u78c1\u76d8\u3002<\/p>\n\n\n\n<p>\u5b9e\u9645\u5e94\u7528\u65f6\uff0c\u6bd4\u5982\u6211\u4eec\u670d\u52a1\u5bf9\u5916\u63d0\u4f9b\u7684\u63a5\u53e3\u65f6\uff0c\u8fd4\u56de\u7684DTO\u5bf9\u8c61\u9700\u8981\u5b9e\u73b0java.io.Serializable\u63a5\u53e3\u5417\uff1f\u7b54\u6848\u662f\u4e00\u822c\u4e0d\u9700\u8981\u3002\u6211\u4eec\u8fd4\u56de\u7ed9\u524d\u7aef\u7684\u6570\u636e\uff0c\u901a\u5e38\u662fJSON\u548cXML\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u8fd9\u662f\u4e00\u4e2aString\uff0cString\u662f\u5b9e\u73b0\u4e86java.io.Serializable\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u7684DTO\u662f\u4e0d\u9700\u8981\u5b9e\u73b0java.io.Serializable\u63a5\u53e3\u7684\u3002<\/p>\n\n\n\n<p>\u9664\u975e\u4f60\u8981\u5c06\u4e00\u4e2a\u5bf9\u8c61\u5199\u5165\u6587\u4ef6\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u7ee7\u627fSerializable\u3002<\/p>\n\n\n\n<p><strong>\u7528\u4e0d\u7528\u6307\u5b9aserialVersionUID\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5982\u679c\u4f60\u4e0d\u5728\u5bf9\u8c61\u4e2d\u5b9a\u4e49serialVersionUID\uff0cJava\u4f1a\u9690\u5f0f\u5b9a\u4e49serialVersionUID\uff0c\u5e76\u6839\u636e\u89c4\u5219\u8bbe\u7f6e\u503c\uff0c\u8fd9\u662f\u4e00\u4e2a\u5371\u9669\u7684\u884c\u4e3a\u3002serialVersionUID\u5bf9\u8c61\u7684\u7248\u672c\u53f7\uff0c\u56e0\u4e3a\u4e00\u65e6\u5bf9\u8c61\u5e8f\u5217\u5316\u5230\u5b58\u50a8\u4ecb\u8d28\u4e0a\uff0c\u5c31\u76f8\u5f53\u4e8e\u6709\u4e86\u526f\u672c\uff0c\u5c31\u8981\u8003\u8651\u6570\u636e\u4e00\u81f4\u6027\uff0c\u5982\u679c\u5c06\u5bf9\u8c61\u5e8f\u5217\u5316\u5206\u53d1\u51fa\u53bb\u4e86\uff0c\u800c\u5bf9\u8c61\u53c8\u88ab\u4fee\u6539\uff0c\u589e\u52a0\u5c5e\u6027\u6216\u6539\u53d8\u5c5e\u6027\uff0c\u6b64\u65f6\u5982\u679c\u6ca1\u6709\u7248\u672c\u53f7\u505a\u63a7\u5236\uff0c\u662f\u5f88\u96be\u5bdf\u89c9\u8fd9\u4e9b\u53d8\u5316\u7684\uff0c\u6240\u4ee5\uff0c\u7406\u8bba\u4e0aserialVersionUID\u7684\u4f7f\u7528\u65b9\u5f0f\u5c31\u662f\uff0c\u6bcf\u5f53\u5bf9\u8c61\u7684field\u505a\u4e86\u53d8\u66f4\u5c31\u5e94\u8be5\u5c06serialVersionUID\u6539\u53d8\uff0c\u901a\u5e38\u662f\u9012\u589e\uff0c\u8fd9\u6837\u7684\u8bdd\uff0c\u5f53\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u65f6\uff0cJava\u5c31\u53ef\u4ee5\u5f97\u77e5\u5e8f\u5217\u5316\u6587\u4ef6\u548c\u5bf9\u8c61\u7684serialVersionUID\u662f\u5426\u5339\u914d\uff0c\u5982\u679c\u4e0d\u5339\u914d\uff0c\u5c31\u4f1a\u629b\u51fa\u5f02\u5e38\uff1ajava.io.InvalidClassException\uff0c\u544a\u77e5\u5e94\u7528\u3002\u6240\u4ee5\u6211\u4eec\u5b9e\u73b0Serializable\u63a5\u53e3\u540e\uff0c\u5e94\u8be5\u5b9a\u4e49serialVersionUID\u53d8\u91cf\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    @Data\n    public class B implements Serializable {\n     \n        private static final long serialVersionUID = 1L;\n     \n        private String name;\n    }<\/pre>\n\n\n\n<p><br><strong>\u670d\u52a1\u5668\u4e0e\u6d4f\u89c8\u5668\u4ea4\u4e92\u65f6\u771f\u7684\u6ca1\u6709\u7528\u5230 Serializable \u63a5\u53e3\u5417?<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5f53\u6211\u4eec\u53ea\u5728\u672c\u5730 JVM \u91cc\u8fd0\u884c\u4e0b Java \u5b9e\u4f8b, \u8fd9\u4e2a\u65f6\u5019\u662f\u4e0d\u9700\u8981\u4ec0\u4e48\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684, \u4f46\u5f53\u6211\u4eec\u9700\u8981\u5c06\u5185\u5b58\u4e2d\u7684\u5bf9\u8c61\u6301\u4e45\u5316\u5230\u78c1\u76d8, \u6570\u636e\u5e93\u4e2d\u65f6, \u5f53\u6211\u4eec\u9700\u8981\u4e0e\u6d4f\u89c8\u5668\u8fdb\u884c\u4ea4\u4e92\u65f6, \u5f53\u6211\u4eec\u9700\u8981\u5b9e\u73b0 RPC \u65f6, \u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u4e86.<\/p>\n\n\n\n<p>\u524d\u4e24\u4e2a\u9700\u8981\u7528\u5230\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684\u573a\u666f, \u662f\u4e0d\u662f\u8ba9\u6211\u4eec\u6709\u4e00\u4e2a\u5f88\u5927\u7684\u7591\u95ee? \u6211\u4eec\u5728\u4e0e\u6d4f\u89c8\u5668\u4ea4\u4e92\u65f6, \u8fd8\u6709\u5c06\u5185\u5b58\u4e2d\u7684\u5bf9\u8c61\u6301\u4e45\u5316\u5230\u6570\u636e\u5e93\u4e2d\u65f6, \u597d\u50cf\u90fd\u6ca1\u6709\u53bb\u8fdb\u884c\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316, \u56e0\u4e3a\u6211\u4eec\u90fd\u6ca1\u6709\u5b9e\u73b0 Serializable \u63a5\u53e3, \u4f46\u4e00\u76f4\u6b63\u5e38\u8fd0\u884c.<\/p>\n\n\n\n<p>\u4e0b\u9762\u5148\u7ed9\u51fa\u7ed3\u8bba:<\/p>\n\n\n\n<p><strong>\u53ea\u8981\u6211\u4eec\u5bf9\u5185\u5b58\u4e2d\u7684\u5bf9\u8c61\u8fdb\u884c\u6301\u4e45\u5316\u6216\u7f51\u7edc\u4f20\u8f93, \u8fd9\u4e2a\u65f6\u5019\u90fd\u9700\u8981\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316.<\/strong><\/p>\n\n\n\n<p>\u7406\u7531:<\/p>\n\n\n\n<p>\u670d\u52a1\u5668\u4e0e\u6d4f\u89c8\u5668\u4ea4\u4e92\u65f6\u771f\u7684\u6ca1\u6709\u7528\u5230 Serializable \u63a5\u53e3\u5417? <\/p>\n\n\n\n<p>\u7f51\u7edc\u4f20\u8f93\u4e2d\u4f7f\u7528\u5b57\u7b26\u4e32\u8fdb\u884c\u4ea4\u4e92\uff0cJSON\u662f\u4e00\u79cd\u7279\u6b8a\u89c4\u8303\u7684\u5b57\u7b26\u4e32\uff0c\u6709\u81ea\u5df1\u7684\u683c\u5f0f\u89c4\u5b9a\uff0c\u4e0eString\u7684\u663e\u793a\u5f62\u5f0f\u4e00\u6837\uff0c\u4f46\u672c\u8d28\u4e0d\u662fString\uff01\u5404\u7aef\u90fd\u652f\u6301JSON\u4e32\u7684\u683c\u5f0f\uff0c\u5c06JSON\u5bb9\u6613\u8f6c\u5316\u4e3aString\u8fdb\u884c\u7f51\u7edc\u4f20\u8f93\u3002<\/p>\n\n\n\n<p>JSON\u683c\u5f0f\u5b9e\u9645\u4e0a\u5c31\u662f\u5c06\u4e00\u4e2a\u5bf9\u8c61\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32, \u6240\u4ee5\u670d\u52a1\u5668\u4e0e\u6d4f\u89c8\u5668\u4ea4\u4e92\u65f6\u7684\u6570\u636e\u683c\u5f0f\u5176\u5b9e\u662f\u5b57\u7b26\u4e32, String \u7c7b\u578b\u5b9e\u73b0\u4e86 Serializable \u63a5\u53e3, \u5e76\u663e\u793a\u6307\u5b9a serialVersionUID \u7684\u503c\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Json\u5bf9\u8c61\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\nString string = JSON.toJSONString(person);\n\n\/\/ \u5b57\u7b26\u4e32\u8f6c\u6210JSon\u5bf9\u8c61\nJSONObject jsonObject = JSON.parseObject(string);<\/pre>\n\n\n\n<p><br>\u6240\u8c13\u5e8f\u5217\u5316\u6307 \u5bf9\u8c61&#8212;&#8212;->JSONString\uff0c\u53cd\u5e8f\u5217\u5316\u6307 JSONString&#8212;&#8212;>JSONObject\u6216\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e8f\u5217\u5316\u7684\u542b\u4e49 \u5e8f\u5217\u5316\u7684\u539f\u672c\u610f\u56fe\u662f\u5e0c\u671b\u5bf9\u4e00\u4e2aJava\u5bf9\u8c61\u4f5c\u4e00\u4e0b\u201c\u53d8\u6362\u201d\uff0c\u53d8\u6210\u5b57\u8282\u5e8f\u5217\uff0c\u8fd9\u6837\u4e00\u6765\u65b9\u4fbf\u6301\u4e45\u5316\u5b58\u50a8\u5230\u78c1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8976"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8976"}],"version-history":[{"count":11,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8976\/revisions"}],"predecessor-version":[{"id":8993,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8976\/revisions\/8993"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}