Java – should I always use generics?
•
Java
I created a unit test:
new Callable() { @Override public Object call() throws .....
I received a warning in Eclipse:
Callable is a raw type. References to generic type Callable<V> should be parameterized
I should write the following code:
new Callable<Object>()
Eliminate warnings, or not? It seems that there is only JUnit test, which makes no sense to add additional code... Thank you
Solution
If your operation does not return a value (or the return has no meaning) You should use Java Lang.void as a type parameter
new Callable<Void>() { public Void call() throws Exception { // do work return null; // <-- This statement is required. } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码