Implement kotlin.jvm.overloads annotation for generating all overloads of a method that has default parameter values.
#KT-2095 Fixed fix backend-side issues with kotlin.jvm.overloads: support the annotation on constructors, generate nullablity annotations on parameters, generate generic signatures, add various tests
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
public class Test {
|
||||
public static String invokeMethodWithOverloads() {
|
||||
C<String> c = new C<String>();
|
||||
return c.foo("O");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class C<T> {
|
||||
[kotlin.jvm.overloads] public fun foo(o: T, k: String = "K"): String = o.toString() + k
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Test.invokeMethodWithOverloads()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Test {
|
||||
public static String invokeMethodWithOverloads() {
|
||||
C c = new C();
|
||||
return c.foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class C {
|
||||
[kotlin.jvm.overloads] public fun foo(o: String = "O", k: String = "K"): String = o + k
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Test.invokeMethodWithOverloads()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class C {
|
||||
[kotlin.jvm.overloads] public fun foo(o: String = "O", i1: Int, k: String = "K", i2: Int): String {
|
||||
return o + k
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
val m = c.javaClass.getMethod("foo", javaClass<Int>(), javaClass<Int>())
|
||||
return m.invoke(c, 1, 2) as String
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class C [kotlin.jvm.overloads] (s1: String, s2: String = "K") {
|
||||
public val status: String = s1 + s2
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = (javaClass<C>().getConstructor(javaClass<String>()).newInstance("O"))
|
||||
return c.status
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class C(val i: Int) {
|
||||
var status = "fail"
|
||||
|
||||
[kotlin.jvm.overloads] constructor(o: String, k: String = "K"): this(-1) {
|
||||
status = o + k
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = (javaClass<C>().getConstructor(javaClass<String>()).newInstance("O"))
|
||||
return c.status
|
||||
}
|
||||
Reference in New Issue
Block a user