question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileTraverser has a poor API for use by Kotlin

See original GitHub issue
Overload resolution ambiguity. All these functions match.
public abstract fun breadthFirst(p0: Path!): (Mutable)Iterable<Path!>! defined in com.google.common.graph.Traverser
public abstract fun breadthFirst(p0: (Mutable)Iterable<Path!>!): (Mutable)Iterable<Path!>! defined in com.google.common.graph.Traverser

Kotlin cannot distinguish between Path and Iterable<Path> making use of this function impossible by Kotlin code.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
chaorencommented, Aug 8, 2022
$ cat Test.kt
import com.google.common.io.MoreFiles
import java.nio.file.Path
import kotlin.io.path.Path

fun main() {
  for (path in MoreFiles.fileTraverser().breadthFirst(Path("."))) {
    println(path)
  }
}
$ wget https://repo1.maven.org/maven2/com/google/guava/guava/31.1-jre/guava-31.1-jre.jar
$ wget https://github.com/JetBrains/kotlin/releases/download/v1.7.10/kotlin-compiler-1.7.10.zip
$ unzip kotlin-compiler-1.7.10.zip
$ ./kotlinc/bin/kotlinc -cp guava-31.1-jre.jar:kotlinc/lib/kotlin-stdlib-jdk7.jar:. Test.kt

It compiles just fine.

$ ./kotlinc/bin/kotlin -cp guava-31.1-jre.jar:kotlinc/lib/kotlin-stdlib-jdk7.jar:. TestKt

It runs just fine as well.

2reactions
fzakariacommented, Aug 8, 2022

It doesn’t show well from the snippet but what I pasted was the error the kotlin compiler was giving me. It cannot distinguish between Iterable<Path> and Path since Path also implements the Iterable Interface.

Interestingly, I got around this by doing:

MoreFiles.fileTraverser().depthFirstPreOrder(listOf(root))

If I do the path without a collection depthFirstPreOrder(root) I get the failure as mentioned above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin documentation of API - Support
I have listened from many developers , that the APIs documentation of Kotlin is poor in STYLE. Like for example if I want...
Read more >
Public API challenges in Kotlin - Jake Wharton
An overused example in every intro-to-Kotlin talk or blog post is comparing a Java “POJO” to a Kotlin data class . Here's yet...
Read more >
Retrofit2 Upload Using RequestBody returns 400 Bad ...
I've updated the content of the question. The Retrofit API class used in my app contains the Request Params which maps to my...
Read more >
GoodReads API from Android with Kotlin | by Andrey Suvorov
I love reading books. I also love to track what I've read. Goodreads is a probably world's largest community of book lovers and...
Read more >
Developing RESTful APIs with Kotlin - Auth0
Let's build and secure a RESTful API with Kotlin and Spring Boot. ... If you have never used Kotlin before, you can still...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found