When I use SonarLint plugin to scan the Java code in IntelliJ IDEA, it shows warning like this:
remove usage of generic wildcard type.
This is the Java code:
import java.util.concurrent.Future; public interface IAsyncTestService { Future<?> submit(Runnable task); }
What should I do to avoid this warnings?
Advertisement
Answer
You should use generic type or actual type for return type of method declaration
public interface IAsyncTestService<T> { Future<T> submit(Runnable task); }
Or
public interface IAsyncTestService { <T> Future<T> submit(Runnable task); }
Or specific type:
public interface IAsyncTestService { Future<String> submit(Runnable task); }