A Service<?>
instance's process
method accepts an instance of a specific but unknown class.
You can't directly create a Service<?>
: you have to create an instance of with a concrete value of the type variable. All of the following are subtypes of Service<?>
: Service<Object>
, Service<Integer>
, Service<Map<String, List<Object>>>
etc. The process
method of these example types expect an Object
, Integer
and Map<String, List<Object>>
respectively.
But the compiler doesn't know which of these it is, so it doesn't allow you to invoke the process
method with a non-null value, because it might be the wrong kind of non-null value.
You can only invoke this with a literal null
, which is the only thing that can be cast to any type.
s.process(null);
If you want to be able to pass Object
into the process
method, you have to make determine
return a Service<Object>
; or remove the type variable from the Service
interface, and make process
just accept Object
.