https://kotlinlang.org logo
#getting-started
Title
# getting-started
f

frank

12/07/2023, 3:33 PM
I was following the guide of
Chronicle-Wire
library, and I found this case: The read operation need a
BiConsumer
value, With Java we can send Setter method but in Kotlin throws compiler error. Some Kotlin expert, can explain to me: Why I can't send the setter method directly and equivalent short-syntax for Kotlin. Method Signature:
Copy code
default <T> WireIn text(T t, @NotNull BiConsumer<T, String> ts) {}
Implementation:
Copy code
// With Java:
wire.read("name").text(this, Data::setName) // Works

// With Kotlin:
wire.read("name").text(this) { obj, name -> obj.name = name } // Works

wire.read("name").text(this, this::setName) // Compile Error: Type mismatch.
wire.read("name").text(this, this::name) // Compile Error: Type mismatch.
s

Sam

12/07/2023, 3:52 PM
I think the syntax you're looking for is
Data::name::set
✔️ 1
f

frank

12/07/2023, 3:55 PM
Sam, thx you.
s

Sam

12/07/2023, 3:56 PM
Glad I could help!