SonarLint V3: Fields in a “Serializable” class should either be transient or serializable for List interface

前端 未结 1 1842
眼角桃花
眼角桃花 2021-01-19 16:16

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

My code is :

public class Page          


        
相关标签:
1条回答
  • 2021-01-19 16:26

    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 {}
    

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

    0 讨论(0)
提交回复
热议问题