久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <legend id='ursqB'><style id='ursqB'><dir id='ursqB'><q id='ursqB'></q></dir></style></legend>

    1. <tfoot id='ursqB'></tfoot>
      • <bdo id='ursqB'></bdo><ul id='ursqB'></ul>
      <i id='ursqB'><tr id='ursqB'><dt id='ursqB'><q id='ursqB'><span id='ursqB'><b id='ursqB'><form id='ursqB'><ins id='ursqB'></ins><ul id='ursqB'></ul><sub id='ursqB'></sub></form><legend id='ursqB'></legend><bdo id='ursqB'><pre id='ursqB'><center id='ursqB'></center></pre></bdo></b><th id='ursqB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ursqB'><tfoot id='ursqB'></tfoot><dl id='ursqB'><fieldset id='ursqB'></fieldset></dl></div>

      <small id='ursqB'></small><noframes id='ursqB'>

    2. 如何生成源代碼來創建我正在調試的對象?

      How do I generate the source code to create an object I#39;m debugging?(如何生成源代碼來創建我正在調試的對象?)
        <tbody id='SRjaE'></tbody>
      • <legend id='SRjaE'><style id='SRjaE'><dir id='SRjaE'><q id='SRjaE'></q></dir></style></legend>
        <tfoot id='SRjaE'></tfoot>

        <small id='SRjaE'></small><noframes id='SRjaE'>

            <i id='SRjaE'><tr id='SRjaE'><dt id='SRjaE'><q id='SRjaE'><span id='SRjaE'><b id='SRjaE'><form id='SRjaE'><ins id='SRjaE'></ins><ul id='SRjaE'></ul><sub id='SRjaE'></sub></form><legend id='SRjaE'></legend><bdo id='SRjaE'><pre id='SRjaE'><center id='SRjaE'></center></pre></bdo></b><th id='SRjaE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SRjaE'><tfoot id='SRjaE'></tfoot><dl id='SRjaE'><fieldset id='SRjaE'></fieldset></dl></div>
              • <bdo id='SRjaE'></bdo><ul id='SRjaE'></ul>
              • 本文介紹了如何生成源代碼來創建我正在調試的對象?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我的典型場景:

                1. 我處理的遺留代碼有一個只有生產中的客戶端才有的錯誤
                2. 我附加了一個調試器,并找出如何在 他們的 系統上重現該問題給 他們的 輸入.但是,我還不知道為什么會發生錯誤.
                3. 現在我想在我的本地系統上編寫一個自動化測試來嘗試重現然后修復錯誤
                1. The legacy code I work on has a bug that only a client in production is having
                2. I attach a debugger and figure out how to reproduce the issue on their system given their input. But, I don't know why the error is happening yet.
                3. Now I want to write an automated test on my local system to try and reproduce then fix the bug

                最后一步真的很難.輸入可能非常復雜,并且包含大量數據.手動創建輸入(例如:P p = new P(); p.setX("x"); p.setY("x"); 想象這樣做 1000 次來創建對象) 非常繁瑣且容易出錯.事實上,您可能會注意到我剛才給出的示例中有一個錯字.

                That last step is really hard. The input can be very complex and have a lot of data to it. Creating the input by hand (eg: P p = new P(); p.setX("x"); p.setY("x"); imagine doing this 1000 times to create the object) is very tedious and error prone. In fact you may notice there's a typo in the example I just gave.

                是否有一種自動化的方法可以從我的調試器中的斷點獲取字段并生成將創建該對象的源代碼,并以相同的方式填充?

                我想出的唯一方法就是序列化這個輸入(例如,使用 Xstream).我可以將其保存到文件中并在自動化測試中將其讀回.這有一個主要問題:如果類以某些方式更改(例如:重命名字段/getter/setter 名稱),我將無法再反序列化對象.換句話說,測試非常脆弱.

                The only thing I've come up with is to serialize this input (using Xstream, for example). I can save that to a file and read it back in in an automated test. This has a major problem: If the class changes in certain ways (eg: a field/getter/setter name is renamed), I won't be able to deserialize the object anymore. In other words, the tests are extremely fragile.

                推薦答案

                眾所周知,Java 標準序列化在對象更改其版本(內容、字段命名)時不是很有用.它適用于快速演示項目.

                Java standard serialisation is well know to be not very usefull when objects change their version ( content, naming of fields). Its fine for quick demo projects.

                更適合您的需求,是 objetcs 支持您自己的(二進制)自定義序列化的方法:
                這并不難,使用 DataOutputStream 寫出一個對象的所有字段.但是現在引入versiong,首先寫出一個versionId.只有一個版本的對象,寫出 versionId 1.這樣以后,當您必須在對象中引入更改時,刪除字段、添加字段、提高版本號.

                More suitable for your needs, is the approach that objetcs support your own (binary) custom serialisation:
                This is not difficult, use DataOutputStream to write out all fields of an object. But now introduce versiong, by first writing out a versionId. Objects that have only one version, write out versionId 1. That way you can later, when you have to introduce a change in your objetcs, remove fields, add fields, raise the version number.

                這樣的 ICustomSerializable 將首先在 readObject() 方法中從輸入流中讀取版本號,并根據版本 ID 調用 readVersionV1() 或例如 readVersionV2().

                Such a ICustomSerializable will then first read out the version number from the input stream, in a readObject() method, and depending on the version Id call readVersionV1() or e.g readVersionV2().

                public Interface ICustomSerializable {
                  void writeObject(DataOutputStream dos);
                  Object readObject(DataInputStream dis);
                }
                
                public Class Foo {
                  public static final VERSION_V1 = 1;
                  public static final VERSION_V2 = 2;
                
                  public static final CURRENT_VERSION = VERSION_V2;
                  private int version;
                
                  private int fooNumber;
                  private double fooDouble;
                
                  public void writeObject(DataOutputStream dos) {
                     dos.writeInt(this.version);
                      if (version == VERSION_V1) {
                          writeVersionV1(dos);
                      } else (version == VERSION_V2) {
                          writeVersionV2(dos);
                      } else {
                         throw new IllegalFormatException("unkown version: " + this.version);
                      }
                  }
                  public void writeVersionV1(DataOutputStream dos) {
                        writeInt(this.fooNumber);
                        writeDouble(this.fooValue);
                  }
                }
                

                需要更多的 getter 和 setter,以及將版本初始化為 CURRENT_VERSION 的構造函數.

                Further getter and setter, and a constructor with initialised the version to CURRENT_VERSION is needed.

                如果您更改或添加適當的讀寫版本,這種序列化是安全的重構.對于使用不受您控制的外部庫中的類的復雜對象,它可以做更多的工作,但字符串、列表很容易序列化.

                This kind of serialisazion is safe to refactoring if you change or add also the appropriate read and write version. For complex objects using classes from external libs not und your controll, it can be more work, but strings, lists are easily serialized.

                這篇關于如何生成源代碼來創建我正在調試的對象?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                  <tbody id='5h5lL'></tbody>
                • <small id='5h5lL'></small><noframes id='5h5lL'>

                • <tfoot id='5h5lL'></tfoot>

                      <bdo id='5h5lL'></bdo><ul id='5h5lL'></ul>

                        <i id='5h5lL'><tr id='5h5lL'><dt id='5h5lL'><q id='5h5lL'><span id='5h5lL'><b id='5h5lL'><form id='5h5lL'><ins id='5h5lL'></ins><ul id='5h5lL'></ul><sub id='5h5lL'></sub></form><legend id='5h5lL'></legend><bdo id='5h5lL'><pre id='5h5lL'><center id='5h5lL'></center></pre></bdo></b><th id='5h5lL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5h5lL'><tfoot id='5h5lL'></tfoot><dl id='5h5lL'><fieldset id='5h5lL'></fieldset></dl></div>

                          <legend id='5h5lL'><style id='5h5lL'><dir id='5h5lL'><q id='5h5lL'></q></dir></style></legend>
                          主站蜘蛛池模板: 亚洲电影一区二区三区 | 久草网址 | 日本aa毛片a级毛片免费观看 | 成人国产一区二区三区精品麻豆 | 久久高清精品 | 天堂中文资源在线 | 91精品国产综合久久精品 | 欧美高清一区 | www.99热这里只有精品 | 91青青草视频 | 中文字幕日韩在线观看 | 欧美8一10sex性hd | 成人国产一区二区三区精品麻豆 | av特级毛片 | 人人爽人人爽 | 一本色道精品久久一区二区三区 | 国产欧美在线视频 | 99视频在线免费观看 | 国产精品美女久久久久久免费 | 日韩精品久久久久久 | 第四色播日韩第一页 | 免费国产一区二区 | 国产精品久久久久久久久久久久 | 亚洲一区二区三区视频 | 天堂在线一区 | 成人性视频免费网站 | 国产乱精品一区二区三区 | 蜜桃传媒av | 色婷婷九月 | 国产三区av | 一级毛片视频 | 97国产精品视频 | 亚洲天堂男人的天堂 | 一区二区视频 | 国产激情视频在线免费观看 | 精品国产一区二区三区久久 | 日韩欧美一区二区三区免费观看 | 欧美群妇大交群中文字幕 | 99热精品在线观看 | 国产小视频精品 | 日日操视频 |