I saw this pattern today and it confused me a lot:
abstract class A {
// does something
static class B extends A {
// does something as well
}
}
Two weird things I found about it:
- Static class can be initialised using
new A.B()
. - Static class is not unique in the application (therefore, not really static), as each initialisation creates a new object.
I am still perturbed as to why to use such a pattern? And does static class
in this context mean, that you can access it's constructors statically, without needing to create an instance of A
, but not really it being a unique in any way in the app?
EDIT:
OK, so I think my understanding of static classes came from C#. I am clear on the staticness of java classes now. But when would you use such a pattern (where inner static class is extending outer abstract one) and why?