Kotlin规范可否

时间:2018-07-28 08:04:11

标签: spring spring-boot kotlin

我正在尝试将Spring Boot 2.0.3与IntelliJ IDEA一起使用。 Kotlin版本是1.2.51。

使用jsr305=strict编译选项时,在whereand部分出现错误。

import com.example.spring_boot.domain.task.Task
import org.springframework.data.jpa.domain.Specification

object TaskSpecification {
    private fun nameContain(name: String?): Specification<Task>? {
        return name?.let {
            Specification { root, query, cb ->
                cb.like(root.get<String>("name"), name)
            }
        }
    }

    fun createSearchSpecification(name: String?
    ): Specification<Task> {
        return Specification.
            where(nameContain(name)).and(nameContain(name))
    }
}

它显示“类型不匹配:必需:规范,找到:规范?”, 当我将它们更改为where(nameContain(name)!!)and(nameContain(name))!!时,错误消失了。

然后我有一个问题。 我看到了2个方法声明。 whereand这两个方法的参数看起来都不是NotNull类型。 为什么会出现这样的错误?

在这里,我附上了声明图像。

where declaration imageand declaration image

Error Image

1 个答案:

答案 0 :(得分:0)

您的private var activityKeyboardDelegate: ActivityKeyboardDelegate? = nil extension UITextField: ActivityKeyboardDelegate { // MARK: - Public methods to set or unset this uitextfield as activityKeyboard. func setAsActivityKeyboard(delegate: ActivityKeyboardDelegate?) { let activityKeyboard = ActivityKeyboard(frame: CGRect(x: 0, y: 0, width: 0, height: kDLActivityKeyboardRecommendedHeight)) self.inputView = activityKeyboard activityKeyboardDelegate = delegate activityKeyboard.delegate = self } func unsetAsActivityKeyboard() { if let activityKeyboard = self.inputView as? ActivityKeyboard { activityKeyboard.delegate = nil } self.inputView = nil activityKeyboardDelegate = nil } // MARK: - activityKeyboardDelegate methods internal func numericKeyPressed(key: Int) { self.text?.append("\(key)") activityKeyboardDelegate?.numericKeyPressed(key: key) } internal func numericBackspacePressed() { if var text = self.text, text.count > 0 { _ = text.remove(at: text.index(before: text.endIndex)) self.text = text } activityKeyboardDelegate?.numericBackspacePressed() } internal func numericSymbolPressed(symbol: String) { self.text?.append(symbol) activityKeyboardDelegate?.numericSymbolPressed(symbol: symbol) } internal func enterPressed() { } internal func dismissPressed() { self.resignFirstResponder() } 返回nameContain(String?)(可为空),它不是Specification<Task>?的有效参数(不可为空)。

使用where(Specification<T>)意味着在return name?.let {... }为空的情况下,函数将返回null