PHP Fatal error ContainerInterface must be compatible with Drupal\Core\DependencyInjection\ContainerInjectionInterface::create(Symfony\Component\DependencyInjection\ContainerInterface $container)

PHP Fatal error:  Declaration of Drupal\redirect_404\Form\SettingsForm::create(Drupal\redirect_404\Form\ContainerInterface $container) must be compatible with Drupal\Core\DependencyInjection\ContainerInjectionInterface::create(Symfony\Component\DependencyInjection\ContainerInterface $container)

Super simple problem with an incredibly scary message.

On my line 40 (not the end of the file, line 184, as the message reported) i have this:

  public static function create(ContainerInterface $container) {

Which is perfect except that ContainerInterface is not actually defined yet. To solve this all i need to do is add the missing ‘use’ statement at the top of my file:

use Symfony\Component\DependencyInjection\ContainerInterface;

is what core/modules/system/src/Form/SiteMaintenanceModeForm.php for instance uses.