How to compile Kotlin unit test code that uses hamcrest 'is'

后端 未结 3 1897
孤独总比滥情好
孤独总比滥情好 2021-02-12 02:55

I want to write a unit test for my Kotlin code and use junit/hamcrest matchers, I want to use the is method, but it is a reserved word in Kotlin.

How can I

3条回答
  •  春和景丽
    2021-02-12 03:26

    You can alias is (say to Is) when you import, using the as keyword.

    E.g:

     import org.hamcrest.CoreMatchers.`is` as Is
    

    See https://kotlinlang.org/docs/reference/packages.html

提交回复
热议问题