Skip to content
Advertisement

What should I do to fix SonarLint warning “remove usage of generic wildcard type”

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);
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement