Is there any way to check whether an object is serializable or not in java?

java

Solution

Use

if(someObj instanceof Serializable) // recommended because it uses 
                                    // the byte code instruction INSTANCEOF

or

if(Serializable.class.isInstance(someObj))

Using `Class.isInstance(someObj)` makes sense if the `Class` should be replaceable at runtime.

For example:

Class<?> someClass == ....; // assign a class object reference dynamically
if(someClass.isInstance(someObj))

Problem

I found that `Object class` in java is not serializable in java at the end when i've wasted much time for a problem. So can anybody knows another class's those are not serializable or any way to check whether that class is serializable?

Original source

Related problems