dimsuz
07/10/2020, 9:35 AMinterface Validator<T> {
fun validate(input: T)
fun and(other: Validator<T>): Validator<T> = TODO()
}
fun <T> andExternal(v1: Validator<T>, v2: Validator<T>): Validator<T> = TODO()
fun <T> isNotEmpty(): Validator<T> = TODO()
fun <T> isNotBlank(): Validator<T> = TODO()
fun doStuff(validator: Validator<String>) { }
fun main() {
// isNotEmpty is highlighted: "not enough information to infer type variable T"
doStuff(isNotEmpty().and(isNotBlank()))
// no error when using external variant of "and", inferred as String!
doStuff(andExternal(isNotEmpty(), isNotBlank()))
}
flosch
07/10/2020, 10:03 AMisNotEmpty
and other functionsdimsuz
07/10/2020, 11:11 AMdoStuff
. Also note, that line with andExternal
has no error, while the only difference from and
(which has an error) is being declared out of the class with this
made into an explicit parameter.flosch
07/10/2020, 1:27 PMdoStuff(isNotEmpty<String>().and(isNotBlank()))
works.
Also this works:
fun test(list: List<String>) {}
test(listOf())
dimsuz
07/10/2020, 1:57 PM