1

When I ask to Eclipse to create automatically a serialVersionUID, there are just two options, default (1L) or the generated one. I want to put in place something to generate a field like

 private static final long serialVersionUID = 2018_07_13_1730L;

so that format is YYYY_MM_YY_HHmm'L'

Is it possible? Maybe via content assist, via a kind of macro or something like this...

asked Jul 13, 2018 at 15:38
3
  • 1
    I think it is possible to do it in Eclipse, but my concern is about if you understand the meaning of this constant and why you need such odd values for them. Commented Jul 13, 2018 at 15:47
  • Absolutely. Either that Id is a random number, or computed based on the fields of your class. Or manually stepped, starting with 0 or 1. I have seen many things since I started with Java 20+ years ago. But never such serial version uids. Commented Jul 13, 2018 at 19:37
  • Thank for your comment: yes we know how Serializable works and meaning of SVUID. Indeed, since we don't have a explicit versioning of represented entities, we use SVUID to vehicolate a meaning too: when object was coded first (or updated later). Commented Jul 17, 2018 at 10:30

1 Answer 1

5

Yes, this is possible via a template (but I'm not sure if this is a good idea here):

  1. Open Window> Preferences: Java> Editor> Templates
  2. Click New...
  3. Enter/choose the following:
    • Name: serialVersionUID
    • Context: Java
    • Description: add serialVersionUID of current date
    • Pattern: private static final long serialVersionUID = ${currentDate:date('yyyy_MM_dd_HHmm')}L;
  4. Hit Ok and Apply and Close to apply the new template

If you type ser and hit Ctrl+Space, also the template should be suggested now.

answered Jul 13, 2018 at 19:30
Sign up to request clarification or add additional context in comments.

1 Comment

Great! It is exactly what I was looking for. Thank you!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.