There is a certain interface:
public interface ViewableParent<C extends AfdxObject> extends Viewable{ interface ListChangeCallback<C>{ void doWhenChange(C object); } ListChangeCallback<C> getAddedSubListCallback(); ListChangeCallback<C> getRemovedSubListCallback(); default ListChangeListener<C> getChangeListener(){ return c -> { while (c.next()){ if (c.wasAdded()) { //Проходимся по добавленным элементам c.getAddedSubList().forEach(e -> { //Вешаем на проперти стиля слушатель, который при изменении стиля потомка меняет стиль у родителя e.styleProperty().addListener((observable, oldValue, newValue) -> refreshStyle(c.getList(), ViewableParent.this,false)); //Выполяняем код add коллбэка if (getAddedSubListCallback()!=null) getAddedSubListCallback().doWhenChange(e); }); //Пересчитываем стиль для родителя исходя из стилей добавляемых потомков refreshStyle(c.getAddedSubList(), ViewableParent.this,true); } else if (c.wasRemoved() || c.wasUpdated()) { //Иначе, если что-то было удалено или обновлено (здесь не уверен в корректности события update) //Так же пересчитываем стиль для родителя refreshStyle(c.getList(), ViewableParent.this, false); //Выполняем код remove коллбэка if (getRemovedSubListCallback()!=null) c.getRemoved().forEach(e -> getRemovedSubListCallback().doWhenChange(e)); } } }; } } The type C parameter denotes the descendant type for the class implementing this interface. 4 out of 5 classes have only one type of descendant, however there is one class in which there are descendants 2. If the class declaration declares 2 times the same interface with different types in the generic, the IDE itself gives an error. Tell me how to circumvent this limitation in terms of architecture?
ViewableParent<B> asVPB()which will return a view: an object of an anonymous class that implements the methods of theViewableParent<B>interface and calls the methods of the main class. - zRrr