Wouter Oet wrote:What exception does it throw?
NullPointerException because the class variable, 'list' is null even it already got initialized in that class (private List<Object> list = new LinkedList<Object>();>
cause by: java.lang.NullPointerException
at <package name>.ClassName.readObject(ClassName.java:#)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:39)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
After doing some research in my own, I figured it out. Reflection do not need the accessor of the class object, just a
string of class' location without knowing the names of the classes, methods etc. at compile time. Now that makes sense that Reflection skips all class variable and all class variables are null no matter if they all already instantiated, implemented or initialized outside the specific method implementation where reflection is accessing into.