Skip to content
Advertisement

Tag: field

Access a private field for a junit test

I am trying to initialize a private field from a class in order to unit test its methods. For that I am using reflection but I am always getting an IllegalArgumentException and I don’t understand what I am doing wrong. My code looks something like this: I get this error when I am trying to run the test: I also

Why does Java have transient fields?

Why does Java have transient fields? Answer The transient keyword in Java is used to indicate that a field should not be part of the serialization (which means saved, like to a file) process. From the Java Language Specification, Java SE 7 Edition, Section 8.3.1.3. transient Fields: Variables may be marked transient to indicate that they are not part of

Advertisement