相关疑难解决方法(0)

kotlin错误的可空性推论没有任何泛型

在春天mvc(5.1.3)我试图做:

val url : String? = null
val matcher: ResultMatcher = MockMvcResultMatchers.forwardedUrl(url)
Run Code Online (Sandbox Code Playgroud)

我得到第二行的编译错误.

来自intellij(kotlinc-jvm 1.3.11):

Error:(230, 56) Kotlin: Null can not be a value of a non-null type String
Run Code Online (Sandbox Code Playgroud)

或者从gradle(kotlin 1.2.71):

 Type mismatch: inferred type is String? but String was expected
Run Code Online (Sandbox Code Playgroud)

spring方法的java源代码是:

/**
 * Asserts the request was forwarded to the given URL.
 * <p>This method accepts only exact matches.
 * @param expectedUrl the exact URL expected
 */
public static ResultMatcher forwardedUrl(String expectedUrl) {
    return result -> assertEquals("Forwarded URL", expectedUrl, …
Run Code Online (Sandbox Code Playgroud)

java spring kotlin

5
推荐指数
1
解决办法
170
查看次数

标签 统计

java ×1

kotlin ×1

spring ×1