Should I create an anonymous class inside method or where? And how should I return the created instance?