![]() |
.. (לתיקייה המכילה) | |
When defining classes we get the warning "Serializable class does not declare a static final serialVersionUID field". What is it and how should we handle it? | |
You can suppress this warning (or simply ignore it). The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. |
Should SafeDispatcher.invoke() return the return value of invoked method? What happens if it's void? | |
If the invoked method completes normally, the value it returns is returned to the caller of SafeDispatcher.invoke(); if the value has a primitive type, it is first appropriately wrapped in an object. If the underlying method return type is void, the invocation returns null. |
When we try to save the object state with Serialization, we might have an | |
Just catch it and print the stack trace. It shouldn't happen. |
How should we deal with overriding of pre/postconditions? Should the overridden conditions be invoked as well? | |
When dynamically invoking a method on an object, overriding based on the runtime type of the target object will occur. Overridden conditions shouldn't be invoked. Remember conditions have no side-effects, so it's O.K for the same method to be invoked several times. |
In Dispatcher.invoke() method, what do you mean by 'illegal arguments' at the first stage in the algorithm? | |
Null references. |
What should we do if an exception is thrown while invoking one of the pre/postconditions? | |
Catch it, print the stack trace and continue. It shouldn't happen. |
When we try to de-serialize an object, a ClassNotFoundException may be thrown. How should we deal with it? | |
Catch it and print the stack trace. It shouldn't happen. |
We see that Dispatcher.invoke() method can throw different types of exceptions. Can we simply write "throws Exception" at the method declaration? | |
No! That's totally missing the point of declaring throwable exceptions. Be specific regarding exceptions both in the declaration and the documentation. |
The code that searches and invokes preconditions came out vary similar to the code that searches and invokes postconditions. We tried to write a common method for both cases but it seems very complicated. Is it ok to leave some duplicated code there? | |
Yes, it is ok to duplicated some code when dealing with the preconditions and the postconditions. |
Should we invoke a private pre-condition of the base class? | |
Do what fits your implementation. That case won't be tested. |