Skip to main content

Using annotations instead of marker interface

1 reply [Last post]
Joined: 2009-04-21

Interfaces like and java.lang.Cloneable don't have any methods and are marker interfaces only. Isn't it better to have annotations like @Serializable or @Cloneable instead of those interfaces in the new version of JDK? Any thought?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-02-04

Performance is a good reason to leave things as they are. I did some testing comparing the performance of the instanceof operator vs Class.isAnnotationPresent. When using jdk1.6/jdk1.7 in both client and server mode, instanceof can be up to 50 times faster.

The absolute time involved is quite small, but it could add up for applications which perform a lot of object serialization. From a design standpoint, annotations make more sense, but for the time being, marker interfaces offer better performance.