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
Sampisa
1,5932 gold badges21 silver badges28 bronze badges
-
1I 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.Luiggi Mendoza– Luiggi Mendoza2018年07月13日 15:47:30 +00:00Commented 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.GhostCat– GhostCat2018年07月13日 19:37:23 +00:00Commented 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).Sampisa– Sampisa2018年07月17日 10:30:30 +00:00Commented Jul 17, 2018 at 10:30
1 Answer 1
Yes, this is possible via a template (but I'm not sure if this is a good idea here):
- Open Window> Preferences: Java> Editor> Templates
- Click New...
- 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;
- Name:
- 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
howlger
35k11 gold badges73 silver badges112 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Sampisa
Great! It is exactly what I was looking for. Thank you!
lang-java