After upgrading Kotlin from 1.1.4 to latest 1.2.22, I got a lot of build warnings:
[WARNING] ... (422, 29) Assigning single elements to varargs in named form is deprecated
The related code is like this:
422 @RequestMapping(value = "/privacy", method = arrayOf(RequestMethod.GET))
423 fun mainLinkPrivacy(request: HttpServletRequest, model: MutableMap<String, Any>): String {
424
425 var lang = request.getParameter("lang")
426
427 if(lang == null || lang.isEmpty())
428 lang = "EN"
429
430 model.put("lang",lang)
431
432 return "/mobile/main/mainlink_privacy"
433 }
And here is the import part:
import org.apache.ibatis.annotations.Param
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.env.Environment
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import javax.servlet.http.HttpServletRequest
And here is my Kotlin version:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<kotlin.version>1.2.21</kotlin.version>
<dokka.version>0.9.15</dokka.version>
<spring.framework.version>4.3.1.RELEASE</spring.framework.version>
</properties>
I think the problem exist in method = arrayOf()
, but how to fix this?
I read the Kotlin release note about this Deprecation: single named argument for vararg, it says:
"For consistency with array literals in annotations, passing a single item for a vararg parameter in the named form (foo(items = i)
) has been deprecated. Please use the spread operator with the corresponding array factory functions:
foo(items = *intArrayOf(1))
There is an optimization that removes redundant arrays creation in such cases, which prevents performance degradation. The single-argument form produces warnings in Kotlin 1.2 and is to be dropped in Kotlin 1.3."
But I still don't find hints about how to fix it.
I think that not deprecated form is value = ["/privacy"], method = [RequestMethod.GET]
.
More documentation on how to use annotations in kotlin can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With