Skip to content

hisano/defer-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

defer-util

defer block in Java like Swift and Go

Introduction

defer-util is a defer block library for releasing resources.

Usage

Use defer block to release resources after tryWithDefer block end.

import static jp.hisano.util.defer.Defer.*;

public class Example {
	public static void main(String[] args) {
		tryWithDefer(() -> {
			Resource resource = new Resource();
			defer(resource::dispose);

			resource.use();
		});
	}

	private static class Resource {
		void use() {
			System.out.println("use");
		}

		void dispose() {
			System.out.println("dispose");
		}
	}
}

License

Copyright 2017 Koji Hisano. Released under the Apache 2.0 license.

About

defer block in Java like Swift and Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages