Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.systems.singleton;
- /*
- * One thing to remember here is, when serializing an enum, field variables are not
- * getting serialized. For example, if we serialize and deserialize the SingletonEnum
- * class, we will lose the value of the int value field
- */
- public enum SingletonEnum {
- INSTANCE;
- int value;
- public int getValue() {
- return value;
- }
- public void setValue(int value) {
- this.value = value;
- }
- }
- public class EnumDemo {
- public static void main(String[] args) {
- SingletonEnum singleton = SingletonEnum.INSTANCE;
- System.out.println(singleton.getValue());
- singleton.setValue(2);
- System.out.println(singleton.getValue());
- }
- }
Add Comment
Please, Sign In to add comment