NetBeans可以为Java类生成自动的串行版本ID吗? [英] Can NetBeans generate an automatic serial version ID for a Java class?

查看:101
本文介绍了NetBeans可以为Java类生成自动的串行版本ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过生成自动串行版本ID来删除某些类的一些警告.在Eclipse中,这很简单-IDE可以自动生成一个并将其添加到类中.但是,我在NetBeans中看不到此功能.是可用的么?如果是这样,它在哪里?如果没有,是否有可以启用它的插件?

I would like to remove some warnings for some classes by generating an automatic serial version ID. In Eclipse, this is trivial to do - the IDE can generate one automatically and add it to the class. However, I don't see this functionality in NetBeans. Is it available? If so, where is it? If not, is there a plugin that can enable it?

推荐答案

实际上,我针对该问题"的解决方案是在项目配置中 停用该警告 (我使用Eclipse,但我猜NetBeans与IMHO相同),这是一个错误的警告:是serialVersion是最安全的选择,因为JVM计算的是启动时唯一的(类似于哈希的哈希值).类),同时显式添加它,这会给造成负担,只有当您对代码进行了不兼容的更改时,您才能谨慎地对其进行更新.

Actually my solution to that "problem" was to deactivate that warning in my project configuration (I use Eclipse but I guess for NetBeans is the same) as IMHO it's a wrong warning: not having a serialVersion is the safest choice because the JVM calculates one that is unique on launch (something like the hash of the class) while adding it explicitly then burdens you to take care to update it if and only if you made incompatible changes to your code.

因此,如果您不关心该值,最好避免使用该值(这样,它仅与肯定兼容的版本兼容,但带有一些误报:它认为这是不兼容,但实际上它会)而不是放置一个固定的值,而您不会(在我的情况下)会在需要时忘记更新,从而导致实际的有效性错误(假阴性:它认为它是兼容的,但是不是).

So, if you do not care about that, it's better to avoid that value (this way it's only compatible with version that are compatible for sure, but with some false-positives: it thinks that's not compatible, but in fact it would) instead of putting there a fixed value that you would (probably, in my case) forget to update when needed, leading to actual validity errors (false-negatives: it thinks that it is compatible but it is not).

这篇关于NetBeans可以为Java类生成自动的串行版本ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆