18

I'm taking a Computer Science class where the assignment boilerplate code is a Java framework where most of the classes (or their superclasses) extend Serializable. What ends up happening then is VSCode complains to me that

The serializable class [insert class name here] does not declare a static final serialVersionUID field of type long"

for nearly all the starting code. I know in other IDEs such as IntelliJ and Eclipse, this specific warning can be suppressed for all Java projects. What would be the equivalent operation in VSCode? I have the Language Support for Java package installed.

The following are reasons why I cannot declare a serialVersionUID or use @SuppressWarnings:

  1. This would force me to modify code which I am not allowed to modify. The prof only wants students to implement certain areas of the framework.

  2. I would need to make these changes to about 30 classes which is less than ideal.

4
  • Why not just declare that field? :) Commented Apr 5, 2018 at 8:48
  • To declare the field, I would need to declare that for dozens of classes, and I'm not supposed to change that portion of the code. I can only change the portions that instructors want us to change. Commented Apr 5, 2018 at 8:53
  • @AndyTurner yes Commented Apr 5, 2018 at 8:53
  • IMHO the question is perfectly valid, with inlineing: new HashMap<String, String>() {{put{"a", "b"}}} this warning is raised, but you certainly do not want this Commented Feb 25, 2019 at 6:16

1 Answer 1

28

Currently Java Support for VSCode reads a file called .settings/org.eclipse.jdt.core.prefs as part of its Eclipse project support. That's a folder called .settings in the root folder of the project, then a file called org.eclipse.jdt.core.prefs in that folder.

In this file, we can suppress the serialVersionUID warning by adding the following line: org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore

Now just restart VS Code, and those warnings will no longer show up.

Sign up to request clarification or add additional context in comments.

Thanks for sharing your solution! Despite many folks arguing against your question on "best practice" or what you "should" do, sometimes we just want to know "how" to do something. Going forward, guess we can use Eclipse to configure the prefs and use those in VS Code.
Shell command to add this: mkdir -p .settings && touch .settings/org.eclipse.jdt.core.prefs && echo "org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore" >> .settings/org.eclipse.jdt.core.prefs
Is there any extension could help us to generate serialVersionUID?
Restarting no longer seems necessary.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.