How to re-generate Magento 2 code in var/generation
First of all, I’d like to draw your attention to this blog post:
To re-generate Magento 2 code in var/generation, you should update generated code every time you upgrade Magento 2 or switch between develop and master branches of the official git repository. Although, you can manually delete content of the var/generation folder – Magento 2 will generate code automatically on its next run – the correct way requires triggering the generation via the Magento 2 CLI tool. Therefore, run magento setup:di:compile from /bin/magento: