Get the UID of the currently logged in user

<?php
$user = \Drupal::currentUser();

// UID
$uid = $user->id();

// Username
$name = $user->getAccountName();

// Email address
$mail = $user->getEmail();

\Drupal::currentUser() leverages the AccountProxy class, which is "a proxied implementation of AccountInterface". This means this object is more or less raed-only and hence has no public setters.

Loading the currently logged in user as a customizable object would take something like:

<?php
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());