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) })
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class JavaCode {
|
||||
public String toJSON(Collection<Integer> collection) {
|
||||
return "[" + collection.stream().map(Object::toString).collect(Collectors.joining(", ")) + "]";
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// ERROR: Unresolved reference: stream
|
||||
// ERROR: Unresolved reference: stream
|
||||
// ERROR: Unresolved reference: Collectors
|
||||
import java.util.stream.Collectors
|
||||
|
||||
internal class JavaCode {
|
||||
fun toJSON(collection: Collection<Int?>): String {
|
||||
return "[" + collection.stream().map({ obj: Object -> obj.toString() }).collect(Collectors.joining(", ")).toString() + "]"
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
public void context() {
|
||||
List<Double> items = new ArrayList<>();
|
||||
items.add(1.0);
|
||||
items.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import java.util.ArrayList
|
||||
import java.util.function.Consumer
|
||||
|
||||
internal class Test {
|
||||
fun context() {
|
||||
val items: MutableList<Double> = ArrayList()
|
||||
items.add(1.0)
|
||||
items.forEach(Consumer { o: Double -> println(o) })
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
fun <T, K> max(coll: Collection<T?>?): T? where T : Any?, T : Comparable<T>?, K : Node?, K : Collection<in K>? {}
|
||||
fun <T, K> max(coll: Collection<T?>?): T? where T : Any?, T : Comparable<T?>?, K : Node?, K : Collection<in K>? {}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
fun <T> max(coll: Collection<T?>?): T? where T : Any?, T : Comparable<T>? {}
|
||||
fun <T> max(coll: Collection<T?>?): T? where T : Any?, T : Comparable<T?>? {}
|
||||
Reference in New Issue
Block a user