79620072

Date: 2025-05-13 16:33:22
Score: 1.5
Natty:
Report link

It's return a bean than was instatinated with constructor (new MyServiceImpl()) - so it's not "anonymous object" but named bean in spring.

That bean stored in spring context for later user by same name or class.

anonymous object - it's a different entity. I think here you refer something like mymethod(new InterfaceName { ...implementation ... })

In other word you compare apples and oranges.

To make it annonymus your notation should looks like:

@Bean public MyService myService() { return new MyServiceInterface() { .... do something ... }; }

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @Bean
  • Low reputation (0.5):
Posted by: user3072571