Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why Kotlin function parameter names break the method call?

Wonder what is wrong with specifying Kotlin function parameter name when calling a function. In some situation it won’t work and I don’t know how to fix it.

For example, this code works fine without specifying the parameters’ names:

assertEquals(
    FakeDataSource.photosList,
    repository.getMarsPhotos(),
)

But the same code with parameters name give me a compiler error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

assertEquals(
    expected = FakeDataSource.photosList,
    actual = repository.getMarsPhotos(),
)

enter image description here

>Solution :

The Kotlin documentation tells us this:

When calling Java functions on the JVM, you can’t use the named argument syntax because Java bytecode does not always preserve the names of function parameters.

You are calling a JUnit method there, written in Java.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading