tags:

views:

96

answers:

3

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
A: 

See the Suppliers class and I guess the methods there will somehow answer your question.

nanda