New J2K: add better support of implicit functional interfaces
#KT-32702 fixed #KT-19327 fixed
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
interface FunctionalI<A, B> {
|
||||
B apply(A x);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class Test {
|
||||
<A, B> B foo(A value, FunctionalI<A, B> fun) {
|
||||
return fun.apply(value);
|
||||
}
|
||||
|
||||
Double toDouble(Integer x) {
|
||||
return x.doubleValue();
|
||||
}
|
||||
|
||||
public double nya() {
|
||||
return foo(1, this::toDouble);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
internal class Test {
|
||||
fun <A, B> foo(value: A, `fun`: FunctionalI<A, B>): B {
|
||||
return `fun`.apply(value)
|
||||
}
|
||||
|
||||
fun toDouble(x: Int): Double {
|
||||
return x.toDouble()
|
||||
}
|
||||
|
||||
fun nya(): Double {
|
||||
return foo(1, FunctionalI { x: Int -> this.toDouble(x) })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
interface FunctionalI<A, B> {
|
||||
fun apply(x: A): B
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Test {
|
||||
<A, B> B foo(A value, FunctionalI<A, B> fun) {
|
||||
return fun.apply(value);
|
||||
}
|
||||
|
||||
Double toDouble(Integer x) {
|
||||
return x.doubleValue();
|
||||
}
|
||||
|
||||
public double nya() {
|
||||
//TODO explicitlly call apply here
|
||||
return foo(1, this::toDouble);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// ERROR: Interface FunctionalI does not have constructors
|
||||
internal class Test {
|
||||
fun <A, B> foo(value: A, `fun`: FunctionalI<A, B>): B {
|
||||
return `fun`.apply(value)
|
||||
}
|
||||
|
||||
fun toDouble(x: Int): Double {
|
||||
return x.toDouble()
|
||||
}
|
||||
|
||||
fun nya(): Double {
|
||||
//TODO explicitlly call apply here
|
||||
|
||||
return foo(1, FunctionalI<Int, Double> { x: Int -> this.toDouble(x) })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
interface FunctionalI<A, B> {
|
||||
B apply(A x);
|
||||
}
|
||||
|
||||
class Test {
|
||||
<A, B> B foo(A value, FunctionalI<A, B> fun) {
|
||||
return fun.apply(value);
|
||||
}
|
||||
|
||||
Double toDouble(Integer x) {
|
||||
return x.doubleValue();
|
||||
}
|
||||
|
||||
public double nya() {
|
||||
return foo(1, this::toDouble);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// ERROR: Type mismatch: inferred type is B? but B was expected
|
||||
// ERROR: Unresolved reference: A
|
||||
// ERROR: Interface FunctionalI does not have constructors
|
||||
internal interface FunctionalI<A, B> {
|
||||
fun apply(x: A): B
|
||||
}
|
||||
|
||||
internal class Test {
|
||||
fun <A, B> foo(value: A, `fun`: FunctionalI<A?, B?>): B {
|
||||
return `fun`.apply(value)
|
||||
}
|
||||
|
||||
fun toDouble(x: Int): Double {
|
||||
return x.toDouble()
|
||||
}
|
||||
|
||||
fun nya(): Double {
|
||||
return foo(1, FunctionalI<Int, Double> { x: A -> this.toDouble(x) })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user