serialversionuid

Use the serialVersionUID or suppress warnings?

微笑、不失礼 提交于 2019-12-17 22:12:53
问题 I want to create a class that, for example, extends HttpServlet? My compiler warns me that my class should have a serialVersionUID. If I know that this object will never be serialized, should I define it or add an annotation to suppress those warnings? What would you do and why? 回答1: I don't know Java best practices, but it occurs to me that if you are claiming that serialization will never happen, you could add a writeObject method which throws. Then suppress the warning, safe in the

Make Java runtime ignore serialVersionUIDs?

怎甘沉沦 提交于 2019-12-17 06:45:47
问题 I have to work with a large number of compiled Java classes which didn't explicitly specify a serialVersionUID. Because their UIDs were arbitrarily generated by the compiler, many of the classes which need to be serialized and deserialized end up causing exceptions, even though the actual class definitions match up. (This is all expected behavior, of course.) It is impractical for me to go back and fix all of this 3rd-party code. Therefore, my question is: Is there any way to make the Java

Make Java runtime ignore serialVersionUIDs?

旧城冷巷雨未停 提交于 2019-12-17 06:45:35
问题 I have to work with a large number of compiled Java classes which didn't explicitly specify a serialVersionUID. Because their UIDs were arbitrarily generated by the compiler, many of the classes which need to be serialized and deserialized end up causing exceptions, even though the actual class definitions match up. (This is all expected behavior, of course.) It is impractical for me to go back and fix all of this 3rd-party code. Therefore, my question is: Is there any way to make the Java

serialversionUID does not match

烂漫一生 提交于 2019-12-13 13:43:20
问题 I am fairly new to java and I have a class Products that is Serializable . I do not know what I did, but my programs stopped working and gave me this error : Exception in thread "main" java.io.InvalidClassException: cockeb.Product; local class incompatible: stream classdesc serialVersionUID = 1288455942608122525, local class serialVersionUID = -558553967080513790 at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:616) at java.io.ObjectInputStream.readNonProxyDesc

Is Java SerialVersionUid of 1L ok? Or does it need to be unique?

守給你的承諾、 提交于 2019-12-13 13:15:11
问题 I have two java classes which implement Serializable. I set both of them to have a serialVersionUid of 1L. A coworker said that all classes must have a unique serial version uid and that the jvm will treat classes as equal if they have the same serial version uid. I thought equality was based on the result of the equals method and not the serial version uid. It was my understanding that the serial version uid was used to indicate the version of the class and that when the class changed in an

Getting rid of the comment above Eclipse-generated serialVersionUID

限于喜欢 提交于 2019-12-10 12:28:44
问题 This has become a pet peeve of mine. I write a class, and implement Serializible . Then eclipse warns me that I don't have a serialVersionUID , so I select " Add generated serialVersionUID " or " Add default serialVersionUID " and I end up with something like this: /** * */ private static final long serialVersionUID = 4049849541314027178L; Most of the time I don't want to add a comment, so I have to go and delete the comment. I would rather the default be no comment, but I've looked through

How to generate serialVersionUID programmatically in Java?

你离开我真会死。 提交于 2019-12-10 02:32:04
问题 I am working on a project that generates Java files. I'd like to be able to optionally add the serialVersionUID as you would with the serialver tool. Is there a way to do this when I generate the Java code, or will I need to ask the user of the tool to provide UIDs manually? To be clear, I'm not looking to do this automatically through Eclipse or the serialver tool, but to do it via Java itself. 回答1: There is a version of the serialver tool source available from OpenJDK. It all comes down to

About generated serialVersionUID in Eclipse

时光毁灭记忆、已成空白 提交于 2019-12-10 02:16:01
问题 Is there any way to generate serialVersionUID in Eclipse serially? By serially I want to mean that if one serializable class has serialVersionUID = 1L, then when I generate serialVersionUID of another class this will be serialVersionUID = 2L. If I manually specify 1L, 2L, 3L and so on, will this can create any problem? Eclipse gave an option to choose "Add generated serial version ID", is this option safe to choose? 回答1: No, it won't create any problem in any of your two circumstances: you

serialVersionUID field warning in eclipse

随声附和 提交于 2019-12-10 02:08:47
问题 I have just started on AWT and made a simple program in it, it works fine but it shows a warning message in eclipse which i don't understand: The serializable class TestGUI does not declare a static final serialVersionUID field of type long I know that the warning message is not related to AWT and there was no need to post my whole code but when i tried to make a SSCCE of the code the warning also disappeared. Since I don't know why this warning is generated i didn't knew which part to retain

Why does the serialVersionUID field exist?

梦想的初衷 提交于 2019-12-07 15:10:19
问题 It has baffled me from the launch of the Serializable interface why I have to incorporate this field in all of my classes. I understand that this interface needs a unique identifier to mark the class but why cant they generate this at run-time. For instance they could generate it using an MD5 hash of the fully-qualified class name or a similar methodology used to handle duplicates in their rare occurrence (Which is, I'm sure, what eclipse does when asked to generate the id anyway). So what I