While I tried to find an answer to another question I noticed that this code compiles in C#:
public void Foo(T obj)
where T : class?
{
}
To allow your class return null value without CS864 warning you can rewrite your code a little bit
public T? Foo(T obj)
where T : class
{
return null;
}
The question about class? is open GitHub issue right now. class? constraint isn't implemented yet and therefore compiler threats it like regular class and generate A null literal introduces a null value when 'T' is a non-nullable reference type for now.
You can also refer to the The issue with T? section in this article to see some details. The code sample above is recommended way to deal with nullable generic type