Please explain the use of the interface Supplier(in Guava) with a suitable example .
A:
It's a way to provide an indirect object. You may want to provide another object each time Supplier.get() is
called.
For example, i have a class called SmtpMailSender
, which takes a hostname for the smtp server. However, the hostname can change at runtime, so instead of taking a String hostname
, it takes a Supplier<String> hostname
.
Christoffer Hammarström
2010-10-25 12:41:27
A:
An example use of Supplier:
http://stackoverflow.com/questions/3636244/thread-safe-cache-of-one-object-in-java/3636791#3636791
Gareth Davis
2010-10-25 12:42:29