How to use t() function in controller? I understand Drupal 8 ControllerBase implements StringTranslationTrait so we can use $this->t() in Controller class. 
But I found in Drupal 8 examples code, they setStringTranslation to use t() function. Here is the code.

public static function create(ContainerInterface $container) {
    $controller = new static(
      $container-&gt;get('database')
    );
    $controller-&gt;setStringTranslation($container-&gt;get('string_translation'));
    return $controller;
  }


The link for their module. https://git.drupalcode.org/project/examples/blob/8.x-1.x/tablesort_example/src/Controller/TableSortExampleController.php

My question is why setStringTranslation when you can just use t() function in the controller.
$this-&gt;t() assumes object context. $this isn't available in the static context of the create method above.

The ControllerBase provides access to t() via a protected function (see below from docs) to it is also not available from the public context. 
setStringTranslation however is a publicly available method.

StringTranslationTrait::t   protected   function    Translates a string to the current language or to a given language.
...
StringTranslationTrait::setStringTranslation    public  function    Sets the string translation service to use.


https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Controller%21ControllerBase.php/class/ControllerBase/8.2.x