I was wondering why, when I use anonymous instanciation together with the instance initializer block, I get a "serializable class" that does not declare a static final field serialVersionUID of type long "compilation warning.
Here is what I mean. Let's say I want to create an instance of ArrayList and at the same time add something to it like this:
ArrayList<Object> arrayList = new ArrayList<Object>(){{add(new Object());}};
If I compile this, everything is fine, but I get the serialVersionUID field without warning. Now ArrayList already implements serializable and has private static final long serialVersionUID
, so why, when I use it like that, does this field seem to βdisappearβ and I get a warning that it is not declared?
source share