@PreDestroy

The @PreDestroy annotation is used for cleanup activities before the object is destroyed, like closing resources. The methods using this annotations will only be called when the Injector itself is destroyed using the destroy method.

import dev.fumaz.infuse.annotation.PreDestroy;

public class FileLogger {
    private File logFile;

    public FileLogger() {
        logFile = openLogFile();
    }

    @PreDestroy
    public void closeLogFile() {
        if (logFile != null) {
            closeFile(logFile);
        }
    }
}

Last updated