It is possible to serialize the primitive 'void' per default, why does not the object 'Void' extend Serializable?
Added example:
The RootImplementation will have a compilation error saying "Void is not within its bound" since it does not extend Serializable. Though would 'someMethod' be declared with 'void' it would be no problem.
public interface Root<R extends Serializable> extends Serializable {
R someMethod();
}
public class RootImplementation implements Root<Void> {
public Void someMethod() {
return null;
}
}
OK, in response to your example, no if you changed the method to void
it would not work, as the method has to have a return type (even if Java now allows covariant return types in overridden methods). The discussion of void
confuses the issue.
What you want to do is declare a type parameter as a "will just return null." Void is generally a good choice for that, but for Void to work, the return type has to be Object. Void can't implement every interface in the API just because someone might want to use it to indicate a null return on a type parameter.
There are three ways to look at your problem: