title: Kotlin method references in place of lambda
body: <p>Consider the following code, where we take chunks of a list, join them and print to stdout:</p>
  
  <pre><code>val l = listOf("1", "2", "3", "4", "5", "6", "7")
  l.chunked(3, { a -&gt; a.joinToString()}).forEach(::println)
  </code></pre>
  
  <p>The code works without a problem. I wanted to change the lambda call (<code>{ a -&gt; a.joinToString()}</code>) to the method reference, like this:</p>
  
  <pre><code>l.chunked(3, l::joinToString).forEach(::println)
  </code></pre>
  
  <p>The code that uses method reference does not compile and the errors given are:</p>
  
  <blockquote>
    <p>Error:(4, 7) Kotlin: Type inference failed: fun 
    Iterable.chunked(size: Int, transform: (List) -> R): List
    cannot be applied to receiver: List  arguments:
    (Int,KFunction6&lt;@ParameterName CharSequence, @ParameterName
    CharSequence, @ParameterName CharSequence, @ParameterName Int,
    @ParameterName CharSequence, @ParameterName(name = "transform")
    ((String) -> CharSequence)?, String>)</p>
    
    <p>Error:(4, 18) Kotlin: Type mismatch: inferred type is
    KFunction6&lt;@ParameterName CharSequence, @ParameterName CharSequence,
    @ParameterName CharSequence, @ParameterName Int, @ParameterName
    CharSequence, @ParameterName(name = "transform") ((String) ->
    CharSequence)?, String> but (List) -> ??? was expected</p>
    
    <p>Error:(4, 21) Kotlin: Type inference failed: fun 
    Iterable.joinToString(separator: CharSequence = ..., prefix:
    CharSequence = ..., postfix: CharSequence = ..., limit: Int = ...,
    truncated: CharSequence = ..., transform: ((T) -> CharSequence)? =
    ...): String cannot be applied to receiver: List  arguments:
    ()</p>
  </blockquote>
  
  <p>Is there a way to compile the code with method references instead of lambda call? I am beginning to learn Kotlin, but suppose that the errors stem from the fact that <code>joinToString</code> uses a number of default arguments?</p>