long getSerialVersionUID


描述

The java.io.ObjectStreamClass.getSerialVersionUID() method returns the serialVersionUID for this class. The serialVersionUID defines a set of classes all with the same name that have evolved from a common root class and agree to be serialized and deserialized using a common format. NonSerializable classes have a serialVersionUID of 0L.

声明

Following is the declaration for java.io.ObjectStreamClass.getSerialVersionUID() method.

public long getSerialVersionUID()

参数

NA

返回值

This method returns the SUID of the class described by this descriptor.

异常

NA

实例

The following example shows the usage of java.io.ObjectStreamClass.getSerialVersionUID() method.

package com.tutorialspoint;

import java.io.*;
import java.util.Calendar;

public class ObjectStreamClassDemo {
   public static void main(String[] args) {

      // create a new object stream class for Integers
      ObjectStreamClass osc = ObjectStreamClass.lookup(Integer.class);

      // get the serial for Integers
      System.out.println("" + osc.getSerialVersionUID());

      // create a new object stream class for Calendar
      ObjectStreamClass osc2 = ObjectStreamClass.lookup(Calendar.class);

      // get the serial for Calendar
      System.out.println("" + osc2.getSerialVersionUID());
   }
}

Let us compile and run the above program, this will produce the following result −

1360826667806852920
-1807547505821590642