Please explain the use of the interface Supplier(in Guava) with a suitable example .
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 singleton 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
.