Junilu Lacar wrote:
Hans Hovan wrote:
If the ProcessorController class contained something like this:
So part of the ProcessorController class would look like this instead:
I think it would make sense since we've linked the interface with its implementation. But it isn't that way. So what is going on here? Any help is appreciated!
If you do that, you've negated the usefulness of programming to an interface instead of an implementation. This design would be far inferior to the other since it's programmed to a specific implementation. What you're seeing is Spring's @Autowire magic in action where it will find a class marked with @Component and inject it into something marked as @Autowired that takes an IProcessor implementation. It can be any IProcessor implementation and not a particular one. This creates a "seam" in your program where you can switch out the implementation with a different one, say for testing purposes, and the program should still work as expected.
Ron McLeod wrote:If your headers are in a map, you could use a ResponseBuilder, iterate through the map entries, and build them in to your response header-by-header.
Mike. J. Thompson wrote:When a Scanner throws an Exception it does not remove the token that caused the Exception from its input. If nextInt throws an exception then repeated calls to nextInt will also throw an Exception. It won't block waiting for more input because it already has input.
You need to clear the invalid token from the input by calling next() in the catch block.