I am converting a codebase to C#8 with nullable reference types. I came across the a method similar to the one in this question but async.
public async Task<T> GetAsync<T>()
{
// sometimes returns default(T); => warning CS8603 Possible null reference return
}
T may be any type, including nullable reference types or nullable value types.
To be clear, I understand WHY this method triggers a warning. What I'd like to know is what annotations can be used to resolve it.
- I know I can use #nullable disable or
default(T)!, but I was hoping for something that's less of a "hammer". - I know I can't use
[return: MaybNull]because that would apply to theTaskitself, not theT.
Is there any other attribute/annotation I can apply to make the compiler happy, or is default(T)! my only option?