Exactly. Just as @PeterS mentioned using enum before it has been properly constructed is causing NPE, because values() method is being called on un-constructed enum.
One more point, I would like to add here that Platform1
and Platform2
both are trying to use unconstructed enum in switch() but NPE is only in Platform1
. Reason behind this is as follows :-
public void initialize(Platform1 platform){
switch (platform) {
Above piece of code from Platform1
enum is using platform
enum object in switch where internally $SwitchMap$Platform1[]
array is used and to initialize this array values()
method is utilized, thus you get NPE. But in Platform2
, switch (platform.displayName)
is comparison on displayName
which is already initialized and a string comparison occurs thus no NPE.
Following are fragments of decompiled code :-
Platform1
static final int $SwitchMap$Platform1[] =
new int[Platform1.values().length];
Platform2
switch ((str = platform.displayName).hashCode())
{
case 3260:
if (str.equals("fb")) {
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…