Can a Method Be Transient Java

transient can only be applied to member variables and not to methods so there is a problem here. Looking at the variable names in your code – things like String s and Object[] aboj – it looks like this source has been generated by decompiling the relevant .

Is it allowed to mark a method as transient?

Every field that is marked as transient will not be serialized. You can use this transient keyword to indicate to the Java virtual machine that the transient variable is not part of the persistent state of an object.

How do you make a field transient in Java?

  1. import java.io.*;
  2. public class Student implements Serializable{
  3. int id;
  4. String name;
  5. transient int age;//Now it will not be serialized.
  6. public Student(int id, String name,int age) {
  7. this.id = id;
  8. this.name = name;
Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest