In Serialization, the class which we want to be serialized has to implement the Serializable interface, otherwise a NotSerializableException is thrown. There are many other examples like that in the various features of Java. Now I just want to know how to bring in such control in custom classes and interfaces. I have an interface called Agent. There can be many different types of Agents, all of them must implement the Agent interface. I also have a class called Node. Nodes create Agents. Now how to bring in control in such a situation, such that an agent always much implement Agent interface, otherwise an exception will be thrown. I might sound a bit vague, but if someone can provide me with the general idea, then I can provide further details if necessary.
Share
If you have a Node method which must take an Agent, you specify that the argument has to be an Agent.
Serialization is a special case. This is because not all types which are serializable are Serializable. Built in types like int[] is serializable but doesn’t implement Serializable. This type of check cannot be done by the compiler and can only be done at runtime.