I wonder when Java Class is instance of Serializable. As I know class is serializable only if it implements Serializable interface. I'm trying to use junit to generate entity class (from some kind of template) and check if it is serializable.
My generated class (which does NOT implement Serializable) looks like:
package test;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.annotation.Generated;
import javax.persistence.Id;
@Entity
@Table( name = MyTestTableDto.TABLE_NAME )
public class MyTestTableDto
{
public static final String TABLE_NAME = "MY_TEST_TABLE";
public static final String COLUMN_MY_ID_FIELD = "MY_ID_FIELD";
public static final String FIELD_MY_ID_FIELD = "myIdField";
@Id
@Column( nullable = true, length = 14, name = COLUMN_MY_ID_FIELD )
private Long myIdField;
public Long getMyIdField()
{
return myIdField;
}
public void setMyIdField( Long aMyIdField )
{
this.myIdField = aMyIdField;
}
}
Test is below:
File generatedFile = new File( GEN_OUTPUT_DIR, File.separator + className + ".java" );
assertTrue( generatedFile.getClass() instanceof Serializable ); //returns true
The result suggest that my generated class is instance of Serializable. My question is why? I think if it does not implements Serializable it should not be instance of it. I searched for an answer but I couldnt find anything.