Java 回调的序列化

Java 回调的序列化,java,serialization,javafx,callback,Java,Serialization,Javafx,Callback,我的应用程序有一些可以配置的设置,还有一些会生成警告。我需要一种方法来保存这些警告,即使应用程序已关闭 我的警告结构如下: public class CustomWarning implements Serializable { private final WarningType warningType; // enum private final String title, description; private final CustomCallback resolu

我的应用程序有一些可以配置的设置,还有一些会生成警告。我需要一种方法来保存这些警告,即使应用程序已关闭

我的警告结构如下:

public class CustomWarning implements Serializable {
    private final WarningType warningType; // enum
    private final String title, description;
    private final CustomCallback resolution;

    public CustomWarning(String title, String description, CustomCallback resolution, WarningType warningType) {
        this.title = title;
        this.description = description;
        this.resolution = resolution;
        this.warningType = warningType;
    }

    public WarningType getWarningType(){
        return warningType;
    }

    public String getTitle(){
        return title;
    }

    public String getDescription() {
        return description;
    }

    public CustomCallback getResolution() {
        return resolution;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof CustomWarning){
            return ((CustomWarning) obj).getWarningType() == warningType;
        }

        return false;
    }
}
上下文如下:例如,用户希望将日志输出设置为高。这将降低应用程序的性能,从而生成警告。此警告将包含标题(“高输出”)和说明(“您已将高设置为日志记录”),并将显示在
对话框中。以下是在
对话框中显示我的警告的函数:

// This will show a new dialog with title, description, and resolve/close buttons
Optional<Boolean> result = DialogFactory.getInstance().createShowWarning().showAndWait();

if(result.isPresent() && result.get())
    myWarning.getResolution().run(); // calls the "callback"
关闭应用程序后,保存
警告列表的最佳方法是什么?已检查以下各项,但没有一项工作正常:

  • 列表的序列化
    :有点困难,因为来自JavaAPI的序列化也序列化了父级,我不想序列化我应用程序中的每个控制器

  • 回调的类名/方法名的序列化:在没有类实例的情况下找不到调用回调的方法,我无法始终重新创建或提供类实例

我提到的方法还有其他的可能性吗,或者有什么新的想法吗?欢迎发表每一条评论


另外:没有外部库会更好

这个应用程序是Android应用程序吗?如果是,请添加标签。如果是Android,则有一些机制可以保存应用程序状态。不,这是一个JavaFX应用程序,很抱歉我忘了提及它。也使用JDK1.8
public interface CustomCallback extends Runnable, Serializable {}