是类型的序列化触发类型的字段

发布于 2025-02-11 15:46:27 字数 505 浏览 1 评论 0原文

假设我们有一些类:

class Foo implements Serializable { }

还有一些接口:

interface Bar extends Serializable { }

如果我们有这样的实现:

class X implements Bar { 
    private final Foo foo; 
}

Sonarqube会警告X类中的字段应该是可序列化或瞬态的。序列化那么为什么会出现此警告? foo的类型是否明确需要序列化,尽管已经通过继承序列化?

在Sonarlint上验证的环境

6.7.0.45926连接到Sonarqube Enterprise Edition 7.9.4(构建35981)以及Sonarlint Standalone 6.7.0.45926在Intellij中。

Let's say we have some class:

class Foo implements Serializable { }

And some interface:

interface Bar extends Serializable { }

If we have an implementation like this:

class X implements Bar { 
    private final Foo foo; 
}

SonarQube will warn that fields should be Serializable or transient in class X. foo in this case is-a Serializable so why does this warning appear? Does the type of foo explicitly need to be Serializable despite already being Serializable through inheritance?

Environment

Verified on SonarLint 6.7.0.45926 connected to SonarQube Enterprise Edition Version 7.9.4 (build 35981), as well as SonarLint standalone 6.7.0.45926 in IntelliJ.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文