In your else
block, instead of:
new ArrayList<String>() {{ add(**breakdown.getId()**); }}
you can use:
new ArrayList<String>(Arrays.asList(breakdown.getId())
or, since you just want a single element ArrayList
, you can use Collections.singletonList
that avoids the creation of temporary varargs array:
new ArrayList<String>(Collections.singletonList(breakdown.getId())
The { ... }
after the new ArrayList<>()
creates an anonymous subclass of ArrayList
, which is an inner class only. Inside an inner class you cannot access non-final
local variables.