How do I load the user object? I need to get the global $user object in Drupal 8. 
I did $account = \Drupal::currentUser(); in the definition of getSubscribedEvents() (a static method) inside a class file.

I get the following error when running drush cr:


  exception
  [error]
  'Drupal\Core\DependencyInjection\ContainerNotInitializedException'
  with message '\Drupal::$container is not initialized yet.
  \Drupal::setContainer() must be called with a real container.' in
  /Applications/MAMP/htdocs/drupal-8.0.x-dev/core/lib/Drupal.php:129


What is wrong in my code?
Since you are using a getSubscribedEvents() static method, I get you are implementing an event subscriber. In this case, you don't access \Drupal::currentUser() (and any static method returning a service that \Drupal exposes) in that method since it would be getting called too early, when Drupal has not yet initialized the dependency container.
That static method is supposed to return a static array describing the events to which the module wants to subscribe; the methods used to subscribe to the events will eventually take a different action basing on the user currently logged-in, and the user permissions that user account has.

Event subscribers are services, and as such they get their dependency injected. Instead of using \Drupal::currentUser(), you define @current_user as one of the arguments of your service, which is what the authentication_subscriber service does.

class: Drupal\Core\EventSubscriber\AuthenticationSubscriber
arguments:
  - '@authentication'
  - '@current_user'
tags:
  - { name: event_subscriber }


If you look at AuthenticationSubscriber::__construct(), you will see how it gets the current user object.

public function __construct(AuthenticationProviderInterface $authentication_provider, AccountProxyInterface $account_proxy) {
  $this-&gt;authenticationProvider = $authentication_provider;
  $this-&gt;filter = ($authentication_provider instanceof AuthenticationProviderFilterInterface) ? $authentication_provider : NULL;
  $this-&gt;challengeProvider = ($authentication_provider instanceof AuthenticationProviderChallengeInterface) ? $authentication_provider : NULL;
  $this-&gt;accountProxy = $account_proxy;
}


In your case, I would use the following code.

mymodule.services.yml

services:
  mymodule.eventsubscriber:
    class: Drupal\mymodule\EventSubscriber\MyModuleSubscriber
    arguments:
      - '@current_user'
    tags:
      - { name: event_subscriber }


src/EventSubscriber/MyModuleSubscriber.php

namespace Drupal\mymodule\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MymoduleSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    // Return the array describing the events to which you subscribe.
  }

  public function __construct(AccountProxyInterface $account_proxy) {
    $this-&gt;accountProxy = $account_proxy;
  }

}


Notice that @current_user is an instance of AccountProxyInterface, so for example, you can check the user has some user permissions with $this-&gt;accountProxy-&gt;hasPermission().