First of all, this is Magento1 code.
$this->_initLayoutMessages('checkout/session');
And you can use following code in Magento2 :
protected $messageManager;
public function __construct(\Magento\Framework\Message\ManagerInterface $messageManager)
{
$this->messageManager = $messageManager;
}
With this, you can call one of the following messages:
$this->messageManager->addSuccess(__("Success"));
$this->messageManager->addError(__("Error"));
$this->messageManager->addWarning(__("Warning"));
$this->messageManager->addNotice(__("Notice"));