0

I see this in some code , and I have a hunch it is not a good practice. What are your opinions ?

@RestController
public class AddController {
    @RequestMapping(value="/Add", method = RequestMethod.POST) 
    public ActionResponse add(@Valid @RequestBody    AddRequest request) {
        // Method does as much as necessary
    }
    static class AddCRequest {              
        public String parameter1;
        public long parameter2;
        public long parameter3;
    }
}
}

Having the static nested class as a parameter of of the methdos of the service , is it good ? Static implies only one instance of the class ? How will it behave with concurrency ? A very good theorical-technical explanation would be appreciated.

Deibys
  • 619
  • 3
  • 9
  • 18
  • You're way off with your "one instance of the class" hunch, see duplicate. – Kayaman Jul 01 '16 at 18:33
  • Can you be more clear ? I am asking about if there are any concurrency issues, This is not duplicate ! – Deibys Jul 01 '16 at 18:35
  • The duplicate explains the difference between inner classes and static nested classes which you do not currently understand. Based on your mistaken understanding you think that there are issues with concurrency (there aren't, at least not in any specific to nested classes way) or that there would only be a single instance of the class (it's not a singleton, it's a normal static nested class). Read the duplicate. In short: there's nothing particularly wrong about the given code, so your hunch is wrong. – Kayaman Jul 01 '16 at 18:38

0 Answers0