Method to resolve generics parameter type in safe way