Skip to content

Instantly share code, notes, and snippets.

@codethereforam
Created March 25, 2024 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codethereforam/3e21a3cb01b734f6ca0cc8d8debf06bc to your computer and use it in GitHub Desktop.
Save codethereforam/3e21a3cb01b734f6ca0cc8d8debf06bc to your computer and use it in GitHub Desktop.
使用Guava实现延迟调用并且缓存第一次调用的值
@Test
void t3() {
Supplier<Long> s = Suppliers.memoize(this::tt);
System.out.println("---------1");
System.out.println(s.get());
System.out.println("---------2");
System.out.println(s.get());
System.out.println("---------3");
System.out.println(s.get());
System.out.println("---------4");
}
long tt() {
System.out.println("hahaha");
return System.currentTimeMillis();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment