pentium said:
Hi folks,
I was just wondering why does Java need empty interfaces like
serializable & cloneable if they don't specify any methods ? What
purpose do they serve then ?
Any pointers would be appreciated.
Thanks,
-MK.
Once use for these interfaces is in the Avalon component framework, in
which you write lots of little components, and then the underlying
framework dictates how those components get used in the course of your
program execution.
One of their marker interfaces has to do with thread safeness. For
example, you can implement the marker interfaces "SingleThreaded", or
"ThreadAware" (I might have gotten these interface names wrong).
The implementation of these classes tells the underlying framework how
to pool instances of your components. For example, if you have
"ThreadSafe" implemented, it will only keep one instance of your
component around because it is thread-safe and all calling methods can
access your component safely. However, for "SingleThreaded" components,
the underlying framework then has to keep a pool of your objects around
and issue them to calling threads, growing the pool as necessary.
It's handy when you want to find out information about an object, but is
wasteful when you have to instantiate an object/component and invoke an
instance method on it. With the marker interfaces you can simply query
the class structure to determine how to handle that particular class.