Silent Death Of The Classic Marker Interface Pattern: Is java.io.Serializable Legacy?
Join the DZone community and get the full member experience.
Join For Free
With the advent of annotations, the approach whereby you implement an interface is actually no longer appropriate. The usage of annotations @Serializable or @Remote is much more elegant. There is an example of this in JSR-181, where an endpoint has only to be annotated with the @WebServce annotation. No additional interface realization/implementation is necessary.
Using an annotation is not the same as implementing an interface, because the type of the class is not going to be extended. Nonetheless, the same effect can be achieved. So, the infrastructure no longer needs to check the type (e.g., with instanceof), but has to check the existence of the annotation via reflection (class#getAnnotation or isAnnotationPresent) instead.
So java.io.Serializable and java.rmi.Remote are actually legacy now!
Opinions expressed by DZone contributors are their own.
Comments