Check if a class implements Serializable in Java

Description

The following code shows how to check if a class implements Serializable.

Example


/*w  w w.  j  av  a 2 s  .  c  o m*/
import java.io.Serializable;
public class Main {
   public static void main(String[] argv){
         System.out.println(isSerializable(String.class));
   }
            
    
  public static boolean isSerializable(final Class c) {
      return (Serializable.class.isAssignableFrom(c));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy