You are returning a Serializable
object, not a Class1
object. There are two routes to doing this, but I recommend the latter:
Serializable s = list.get(1);
if (s instanceof Class1) {
Class1 clazz = (Class1) s;
clazz.getA();
} //etc...
Or, using a common interface:
public interface YourClass extends Serializable {
public int getA();
}
//...
List<YourClass> list = new ArrayList<>();