Lombok @Cleanup Annotation with user defined close method

If the type of object you’d like to cleanup does not have a close() method, but some other no-argument method, you can specify the name of this method like so:

@Cleanup("dispose") org.eclipse.swt.widgets.CoolBar bar = new CoolBar(parent, 0);

By default, the cleanup method is presumed to be close(). A cleanup method that takes 1 or more arguments cannot be called via @Cleanup.

Specify the method to be executed
package sample.lombok;import lombok.Cleanup;public class Main {    public static void main(String... args) {        @Cleanup("dispose") Main m = new Main();    }    Public  Void  Close ()  {         System . Out . Println ( "Close method was called" );     }    public  void  dispose ()  {         System . out . println ( "dispose method called" );     } }
Execution result
dispose method called