Consider the class below. If I run Findbugs against it it will give me an error (\"Non-transient non-serializable instance field in serializable class\") on line 5 but not o
You could use a capture helper to ensure that a passed in Set supports two interfaces:
private static class SerializableTestClass & Serializable> implements Serializable
{
private static final long serialVersionUID = 1L;
private final T serializableSet;
private SerializableTestClass(T serializableSet)
{
this.serializableSet = serializableSet;
}
}
public static class PublicApiTestClass
{
public static & Serializable> Serializable forSerializableSet(T set)
{
return new SerializableTestClass(set);
}
}
In this way you can have a public API that enforces Serializable without checking/requiring specific implementation details.