Better solution for anonymous classes