CredentialsCase[] (CredentialsCase... cases) { List<CredentialsCase> exCases = new ArrayList<>(); for (TypeHandler typeHandler : myCredentialsType2Handler.values()) { final TypeHandlerEx handlerEx = ObjectUtils.tryCast(typeHandler, TypeHandlerEx.class); if (handlerEx != null) { exCases.add(new CredentialsCase() { @Override public CredentialsType getType() { return handlerEx.getType(); } @Override public void process(Object credentials) { processEx(handlerEx.getEditor(), credentials); } }); } } return ArrayUtil.mergeArrays(cases, exCases.toArray(new CredentialsCase[0])); }