Hi! I have a very easy question, but I really don’t understand how it works.
I have two interfaces:
interface Recipient
interface EmailRecipient : Recipient {
fun getEmailAddress(): String
}
I want to create a builder function, that get a String and return an instance of EmailRecipient:
fun buildEmailRecipient(email: String): EmailRecipient {
return object : EmailRecipient {
override fun getEmailAddress(): String {
return email
}
}
}
I would like to write it as lambda. But my code like
fun buildEmailRecipient(email: String): EmailRecipient
= EmailRecipient {email}
doesn’t work.
EmailRecipient is a Supplier, isn’t it? And code like
fun buildSomeSupplier(s: String): Supplier<String> = Supplier { s }
works.
Can you help me please? Why my EmailRecipient interface can’t be present as lambda?