Given the following not very useful code:
package com.something; import java.util.ArrayList; import java.util.Collection;
(Please correct my understanding if it is not so!)
The second call to fancy() is a compiler error, because Java cannot infer any common type between the two arguments (cannot infer Object , since the second parameter must be Collection .)
The plain() call is not a compiler error, because Java passes a generic Object type between two arguments.
I recently met code that had a method signature similar to plain() .
My question is:
Is plain() signature useful for anything?
Perhaps the person who wrote this code thought that the plain() signature would ensure that both parameters had the same type at compile time, which is obviously not the case.
Is there any difference or usefulness for writing a method with a signature of type plain() , and not just for defining both parameters as Object s?
java generics type-inference
segfault
source share