In Java, how can you declare a variable non-serializable?
Answered
In Java, how can you declare a variable non-serializable? When it is required?
Best answer
A variable can be made non-serializable by declaring it as transient by using ‘transient’ keyword. By default all variables are persistent.
Variables can be marked ‘transient’ when you want to avoid persisting them, you don’t have the necessity to maintain their state.