Recently I came across the statement in the Fragment docs:
All subclasses of Fragment must include a public no-argument constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it. If the no-argument constructor is not available, a runtime exception will occur in some cases during state restore.
In this regard, I have already read the following posts:
1. Explicitly writing default empty constructor.
2. Default constructors and inheritance in Java.
3. Java entity - why do I need an empty constructor?.
4. Do fragments really need an empty constructor?.
If I recall correctly, Java automatically provides a default empty constructor when no constructor is defined (as is the case with Fragment
s), so why do we need to define one anyway ? What purpose does this serve ? And what difference does it make if we don't define a default constructor in a Fragment
?