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

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

        • <bdo id='y96q9'></bdo><ul id='y96q9'></ul>

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

        SonarLint V3:“Serializable"中的字段;对于 List 接口,类应该是瞬态的或可序列化

        SonarLint V3: Fields in a quot;Serializablequot; class should either be transient or serializable for List interface(SonarLint V3:“Serializable中的字段;对于 List 接口,类应该是瞬态的或可序列化的)
            <tbody id='LewAH'></tbody>
        1. <small id='LewAH'></small><noframes id='LewAH'>

            <legend id='LewAH'><style id='LewAH'><dir id='LewAH'><q id='LewAH'></q></dir></style></legend>

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

                  本文介绍了SonarLint V3:“Serializable"中的字段;对于 List 接口,类应该是瞬态的或可序列化的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的问题与 this 非常相似 除了我在 SonarLint V3 (squid:S1948) 中遇到的这个问题.

                  My question is very similar to this except that this issue I have encountered in SonarLint V3 (squid:S1948).

                  我的代码是:

                  public class Page<T> implements Serializable {
                  
                      Summary summary;
                      List<T> elements;
                  
                      public Page() {
                          summary = new Summary();
                      }
                  
                      public List<T> getItemsReceived() {
                          return elements;
                      }
                  
                      public void setItemsReceived(List<T> list) {
                          this.elements = list;
                      }
                  
                      public Summary getSummary() {
                          return summary;
                      }
                  
                      public void setSummary(Summary summary) {
                          this.summary = summary;
                      }
                  
                  }
                  

                  摘要对象实现可序列化.

                  The Summary Object implements serializable.

                  public class Summary implements Serializable {
                  
                      int offset;
                      int limit;
                      long totalElements;
                  
                      public int getOffset() {
                          return offset;
                      }
                  
                      public void setOffset(int offset) {
                          this.offset = offset;
                      }
                  
                      public int getLimit() {
                          return limit;
                      }
                  
                      public void setLimit(int limit) {
                          this.limit = limit;
                      }
                  
                      public long getTotalNumberOfElements() {
                          return totalElements;
                      }
                  
                      public void setTotalNumberOfElements(long totalNumberOfElements) {
                          this.totalElements = totalNumberOfElements;
                  
                      }
                  
                  }
                  

                  现在,如果我将 List 替换为 ArrayList ,那么 SonarLint 中会出现另一个警告,即我们应该使用接口而不是实现类.

                  Now, If I replace List by ArrayList , then another warning in SonarLint arises that we should be using interface instead of implementation classes.

                  我认为这可能会在 SonarQube 中解决,但对于 SonarLint 我不知道.这是一个错误还是我做错了什么?

                  I think this might be resolved in SonarQube but for SonarLint I don't know. Is this a bug or am I doing something wrong ?

                  推荐答案

                  SonarLint 是对的.问题是不能保证 elements 字段是可序列化的.您需要像这样在 T 类型上添加类型绑定

                  SonarLint is right. The problem is that there is no guarantee that elements field is serializable. You need to add type bound on T type like this

                  public class Page<T extends Serializable> implements Serializable {}
                  

                  这样,如果为列表选择的实现是可序列化的(Java 中的标准集合类型也是如此),则列表将是可序列化的.

                  This way the list will be serializable if implementation chosen for it is serializable (which is true for standard collection types in Java).

                  这篇关于SonarLint V3:“Serializable"中的字段;对于 List 接口,类应该是瞬态的或可序列化的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Slf4j LoggerFactory.getLogger and sonarqube(Slf4j LoggerFactory.getLogger 和 sonarqube)
                  Security - Array is stored directly(安全性 - 数组直接存储)
                  SonarQube quot;Class Not Foundquot; during Main AST Scan(SonarQube“找不到类在主 AST 扫描期间)
                  Integrate Spock#39;s test with Sonar(将 Spock 的测试与声纳集成)
                  How do I make Hudson/Jenkins fail if Sonar thresholds are breached?(如果违反声纳阈值,我如何让 Hudson/Jenkins 失败?)
                  automatically add curly brackets to all if/else/for/while etc. in a java code-base(自动将大括号添加到 java 代码库中的所有 if/else/for/while 等)
                        <bdo id='6z6Qh'></bdo><ul id='6z6Qh'></ul>

                        <tfoot id='6z6Qh'></tfoot>
                      • <legend id='6z6Qh'><style id='6z6Qh'><dir id='6z6Qh'><q id='6z6Qh'></q></dir></style></legend>
                          <tbody id='6z6Qh'></tbody>

                      • <small id='6z6Qh'></small><noframes id='6z6Qh'>

                      • <i id='6z6Qh'><tr id='6z6Qh'><dt id='6z6Qh'><q id='6z6Qh'><span id='6z6Qh'><b id='6z6Qh'><form id='6z6Qh'><ins id='6z6Qh'></ins><ul id='6z6Qh'></ul><sub id='6z6Qh'></sub></form><legend id='6z6Qh'></legend><bdo id='6z6Qh'><pre id='6z6Qh'><center id='6z6Qh'></center></pre></bdo></b><th id='6z6Qh'></th></span></q></dt></tr></i><div id='6z6Qh'><tfoot id='6z6Qh'></tfoot><dl id='6z6Qh'><fieldset id='6z6Qh'></fieldset></dl></div>