ImRaphael
ImRaphael

Reputation: 206

Array as argument for ant matchers in spring boot kotlin

In spring boot when using java its posible to pass array of strings as an argument to antMatchers

 private static final String[] LINK_PBL = {
            "/webjars/**",
            "/css/**",
            "/js/**",
            "/images/**",
            "/",
            "/about/**",
            "/contact/**",
            "/error/**/*"

    };

.antMatchers(LINK_PBL)

above example works in java, bottom one does not work in kotlin.

  private val LINK_PBL = arrayOf(
            "/webjars/**",
            "/css/**",
            "/js/**",
            "/index",
            "/images/**",
            "/",
            "/about/**",
            "/contact/**",
            "/error/**/*"

    )
antMatchers(LINK_PBL)

It shows an error that noone of the functions can be called for given argument.

Upvotes: 1

Views: 818

Answers (1)

Sergii Zhevzhyk
Sergii Zhevzhyk

Reputation: 4202

It can be passed using the spread operator*:

antMatchers(*LINK_PBL)

This function uses the vararg keyword to define variable number of arguments. Kotlin makes a clear distinction between arrays and variable arguments. I assume it is done in order to prevent erroneous invocations.

Upvotes: 2

Related Questions