Java 如何在 Intellij 中生成串行版本 UID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24573643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 13:07:54  来源:igfitidea点击:

How to generate serial version UID in Intellij

javaserializationintellij-idea

提问by nazar_art

When I used Eclipseit had a nice feature to generate serial version UID.

当我使用Eclipse 时,它有一个很好的功能来生成串行版本的 UID。

But what to do in IntelliJ?

但是在 IntelliJ 中该怎么做呢?

How to choose or generate identical serial version UID in IntelliJ?

如何在 IntelliJ 中选择或生成相同的串行版本 UID?

And what to do when you modify old class?

修改旧类时怎么办?

If you haven't specify the id, it is generated at runtime...

如果您没有指定id,它将在运行时生成...

采纳答案by Serhii Maksymchuk

Without any plugins:

没有任何插件:

You just need to enable highlight: (Idea v.2016, 2017 and 2018, previous versions may have same or similar settings)

您只需要启用高亮:(Idea v.2016、2017和2018,之前的版本可能有相同或相似的设置)

File -> Settings -> Editor -> Inspections -> Java -> Serialization issues -> Serializable class without 'serialVersionUID' - set flag and click 'OK'. (For Macs, Settings is under IntelliJ IDEA -> Preferences...)

文件 -> 设置 -> 编辑器 -> 检查 -> Java -> 序列化问题 -> 没有“serialVersionUID”的可序列化类 - 设置标志并单击“确定”。(对于 Mac,设置位于 IntelliJ IDEA -> 首选项...)

Now, if your class implements Serializable, you will see highlight and alt+Enter on class name will propose to generate private static final long serialVersionUID.

现在,如果您的类实现了Serializable,您将看到突出显示,并且类名上的 alt+Enter 将建议生成private static final long serialVersionUID.

UPD: a faster way to find this setting - you might use hotkey Ctrl+Shift+A(find action), type Serializable class without 'serialVersionUID'- the first is the one.

UPD:找到此设置的更快方法 - 您可以使用热键Ctrl+Shift+A(查找操作),输入Serializable class without 'serialVersionUID'- 第一个是。

回答by Meo

回答by Patch Rhythm

IntelliJ IDEA Plugins / GenerateSerialVersionUID https://plugins.jetbrains.com/plugin/?idea&id=185

IntelliJ IDEA 插件/生成SerialVersionUID https://plugins.jetbrains.com/plugin/?idea&id=185

very nice, very easy to install. you can install that from plugins menu, select install from disk, select the jar file you unpacked in the lib folder. restart, control + ins, and it pops up to generate serial UID from menu. love it. :-)

非常好,非常容易安装。您可以从插件菜单安装它,选择从磁盘安装,选择您在 lib 文件夹中解压的 jar 文件。重启,control + ins,弹出菜单生成串口UID。爱它。:-)

回答by mykey

with in the code editor, Open the class you want to create the UID for , Right click -> Generate -> SerialVersionUID. You may need to have the GenerateSerialVersionUID plugin installed for this to work.

在代码编辑器中,打开要为其创建 UID 的类,右键单击 -> 生成 -> SerialVersionUID。您可能需要安装 GenerateSerialVersionUID 插件才能使其工作。

回答by jeremysprofile

Easiest method: Alt+Enteron

最简单的方法:Alt+ Enteron

private static final long serialVersionUID = ;

IntelliJ will underline the space after the =. put your cursor on it and hit alt+Enter(Option+Enteron Mac). You'll get a popover that says "Randomly Change serialVersionUID Initializer". Just hit enter, and it'll populate that space with a random long.

IntelliJ 将在=. 将光标放在上面并点击alt+ Enter(Mac 上的Option+ Enter)。你会得到一个弹出窗口,上面写着“随机更改 serialVersionUID 初始化程序”。只需按回车键,它就会用随机长度填充该空间。