Because in the first example, you create an anonymous subclass of ArrayList through "dual-binding initialization", and ArrayList implements the Serializable interface. SerialVersionUID is used during deserialization, and it is good practice to provide one, although not necessarily. Your IDE is probably configured to notify you of these alerts.
In your second example, you are not creating an anonymous subclass of ArrayList, just create an instance and call its methods.
source share