I have gone through the following tutorial :
http://www.javaworld.com/community/node/2915
And after reading the above article, I feel, that it is not possible to
write a Marker interface, because, how can you instruct compiler, that, what tag,
it embed in the .class file for your Marker interface.
Please correct me, if I am wrong.
cheers 🙂
Aha!! I understand your confusion.
CA FEthe magic number for a bytecode file; i.e. the file you get when you compile a class. The bytecode file for ANY class has this magic number, whether it is serializable or not serializable.AC EDis the magic number a serialized Java object file; i.e. the file you serialize an instance of some serializable class.You are mixing up two different concepts (classes and instances) and their respective representations.
So the answer to your question is … of course you can write your own marker interfaces! There is nothing special to the compiler about a class that implements a marker interface.
However, it would be impossible to duplicate the implementation of Java object deserialization in pure Java. Object deserialization uses a backdoor (the
Unsafe.allocateInstancemethod) to create objects without invoking their constructors. AFAIK, this method cannot be called from normal Java code. (And even if it can, it shouldn’t be …)