0

what's different in public protected method?

    @RequestMapping("/")
    String home(){
       "Hello World!"
    }

    @RequestMapping("/")
    public String home(){
       "Hello World!"
    }

Is it just mean public and protected in java?

Jax
  • 3
  • 4
  • 1
    Possible duplicate of [Difference among 'public', 'default', 'protected', and 'private'](http://stackoverflow.com/questions/215497/difference-among-public-default-protected-and-private) – Relequestual Jul 08 '16 at 09:09
  • What do you mean by "default protected" and "public protected"? – a better oliver Jul 08 '16 at 10:11

1 Answers1

1

In this case, since no one other than Spring and your unit tests should call these methods, making them public or protected doesn't change much.

I would leave them public because

  • protected makes it look like the method is intended to be overridden, which it's not
  • public makes it look like the method is intended to be called from the outside world, which it is (except it's being called through HTTP, and Spring is the one actually calling the method)
  • if you need to make that method transactional, or otherwise proxied, then the method should be public
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255