Why does interface return object instead of generic parameter type?

115 Views Asked by At
namespace Microsoft.AspNetCore.Http;
public interface IEndpointFilter
{
    ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next);
}

I am wondering why the above interface is not made as follows?

namespace Microsoft.AspNetCore.Http;
public interface<T> IEndpointFilter
{
    ValueTask<T?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next);
}
1

There are 1 best solutions below

0
Ali Aslani On

while using generic type, you force the developer to use a type to implement the methods which may be confusing or not necessary here