Drupal 8 - $link and $url objects

/** @var Drupal\Core\Utility\LinkGenerator $linkGenerator */
$linkGenerator = \Drupal::service('link_generator');

/** @var Drupal\Core\Url $installerUrl */
$installerUrl = Drupal\Core\Url::fromUri('base://core/install.php');

/** @var Drupal\Core\Url $installerLink */
$installerLink = $linkGenerator->generate('Install', $installerUrl);

// Print variable or invoke `__toString` magic method directly:  { "<a href="/core/install.php">Install</a>" }
var_dump($installerLink->__toString());

/** @var Drupal\Core\Url $externalUrl */
$externalUrl = Drupal\Core\Url::fromUri('https://www.keboca.com/notes', ['query' => ['foo' => 'bar']]);

/** @var Drupal\Core\GeneratedLink $externalLink */
$externalLink = $linkGenerator->generate('KEBOCA - Notes', $externalUrl);

// Print variable or invoke `__toString` magic method directly:  { "<a href="https://www.keboca.com/notes?foo=bar">KEBOCA - Notes</a>" }
var_dump($externalLink->__toString());

/** @var Drupal\Core\Url $internalUrl */
$internalUrl = Drupal\Core\Url::fromRoute('system.admin');

/** @var Drupal\Core\GeneratedLink $internalLink */
$internalLink = $linkGenerator->generate('Admin page', $internalUrl);

// Print variable or invoke `__toString` magic method directly:  { "<a href="/admin">Admin page</a>" }
var_dump($internalLink->__toString());

// It returns the raw URL value:  { "/admin/structure/types" }
$url = \Drupal::url('entity.node_type.collection');

/** @var  Drupal\Core\StringTranslation\TranslatableMarkup $text */
$text = t('Visit the <a href=":url">content types</a> page', [
  ':url' => $url
]);

// To render translatable as final HTML: { "Visit the <a href="/admin/structure/types">content types</a> page" }
var_dump($text->render());