Google Guava Supplier Example

前端 未结 6 1135
感情败类
感情败类 2021-02-02 07:23

Please explain the use of the interface Supplier(in Guava) with a suitable example .

6条回答
  •  梦如初夏
    2021-02-02 08:00

    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 hostname.

提交回复
热议问题