EX00 - Supplier

Moderatoren: pmueller, SE - Design and Construction

Benutzeravatar
UdoWeber
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 156
Registriert: 8. Nov 2009 15:13

EX00 - Supplier

Beitrag von UdoWeber »

I use Supplier the first time and have a question:

If I use a Supplier as an argument for the default debug method, then I can only use the assignment of a lambda expression as parameter and not a String anymore. Do I understand something wrong here or should we use it that way?

Thanks for your help, Udo.

Benutzeravatar
AizazZaidee
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 106
Registriert: 20. Apr 2016 22:49

Re: EX00 - Supplier

Beitrag von AizazZaidee »

Supplier has a get( ) method that will be called lazily and you cannot pass a String because param required would be something like Supplier<String> and it's functional interface so probably you can also do like someMethod( ( ) -> "some string")

It can be used as the assignment target for a lambda expression or method reference only.

Best,
AZ

Benutzeravatar
UdoWeber
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 156
Registriert: 8. Nov 2009 15:13

Re: EX00 - Supplier

Beitrag von UdoWeber »

Ok, but in result my debug method for example has the signature:

ILogger.debug(Supplier<String> msg)

And not just debug(String msg), is this ok? I see no other way to do it.

Greets Udo

Benutzeravatar
UdoWeber
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 156
Registriert: 8. Nov 2009 15:13

Re: EX00 - Supplier

Beitrag von UdoWeber »

Maybe some official answer? ;-)

pmueller
Moderator
Moderator
Beiträge: 87
Registriert: 25. Jan 2018 11:14

Re: EX00 - Supplier

Beitrag von pmueller »

Hi,

this signature is fine.

Best,
Patrick

Antworten

Zurück zu „Software Engineering - Design and Construction“