1

I found this while reading about programmatic configuration of servlets:

ServletRegistration.Dynamic addServlet(String name, String servletClass)

This one: ServletRegistration.Dynamic baffles my core Java syntax knowledge. What does it mean?

Question Everything
  • 2,249
  • 4
  • 20
  • 24

3 Answers3

2

That is a static nested interface. It has been defined in the source code as

public interface ServletRegistration {

  public static interface Dynamic {
    // ..
  }
  // ..
}

Read more about Nested Classes. The concepts apply to interfaces as well.

Nested classes that are declared static are simply called static nested classes. Non-static nested classes are called inner classes.

Also, take a look at this SO link: Java inner class and static nested class

Community
  • 1
  • 1
Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
1

Look at the documentation on ServletRegistration

There you can see Dynamic is a nested class

Evans
  • 1,589
  • 1
  • 14
  • 25
1

As per Java Docs, ServletRegistration.Dynamic is a sub interface of Interface ServletRegistration

public static interface ServletRegistration.Dynamic extends ServletRegistration, Registration.Dynamic

What does it mean?

It means that return type of addServlet is ServletRegistration.Dynamic

And how is this possible?

This was possible but ServletRegistration.Dynamic is a sub-interface.

Vikas V
  • 3,176
  • 2
  • 37
  • 60