S2326: T is not used in the interface

My SonarLint for Eclipse version: 7.1.0.39158

I have an interface with a generic parameter, where the only use of the parameter is that it is substituted in the declaration of its inner implementations. But SonarLint still indicates the above error (“S2326: T is not used in the interface.”) as if the parameter was not used.

public interface Type<T> { // this T is necessary
    
    public static final class Int extends Type<Integer> { /*...*/ }

    public static final class String extends Type<String> { /*...*/ }
    
}
1 Like

Hi @davidsusu,

Can you explain your use case a bit more concretely? From the code you posted, I can’t tell what purpose the type parameter is supposed to serve.

Cheers,
Sebastian

I have a similar issue when creating a generic entity repository

public interface IEntityRepository<T> : IEntityRepository where T : DbContext
{

}

the only purpose of T is to indicate which DbContext to use, which will only be used in the concrete class constructor to set the DB context.

public class EntityRepository<T> : EntityRepository, IEntityRepository<T> where T : DbContext
{
    public EntityRepository(T context)
        : base(context)
    {
    }
}