KT-715. T.javaClass & TypeInfo.javaClassForType
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
|
||||
val test = "lala".javaClass
|
||||
|
||||
val test2 = typeinfo<Int>().javaClassForType
|
||||
|
||||
fun box(): String {
|
||||
if(test.getCanonicalName() != "java.lang.String") return "fail"
|
||||
System.out?.println(test2.getCanonicalName())
|
||||
if(test2.getCanonicalName() != "java.lang.Integer") return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -72,4 +72,8 @@ public class StdlibTest extends CodegenTestCase {
|
||||
public void testKt828 () {
|
||||
blackBoxFile("regressions/kt828.kt");
|
||||
}
|
||||
|
||||
public void testKt715 () {
|
||||
blackBoxFile("regressions/kt715.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package std
|
||||
|
||||
import java.lang.Class
|
||||
import java.lang.Object
|
||||
|
||||
val <T> T.javaClass : Class<T>
|
||||
get() = jet.runtime.Intrinsics.getJavaClass(this) as Class<T>
|
||||
|
||||
val <T> TypeInfo<T>.javaClassForType : Class<T>
|
||||
get() = (this as org.jetbrains.jet.rt.TypeInfoImpl<T>).getJavaClass().sure()
|
||||
@@ -1,6 +1,7 @@
|
||||
package jet.runtime;
|
||||
|
||||
import jet.Function0;
|
||||
import jet.TypeInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -18,6 +19,10 @@ public class Intrinsics {
|
||||
public static void throwNpe() {
|
||||
throw new JetNullPointerException();
|
||||
}
|
||||
|
||||
public static <T> Class<T> getJavaClass(T self) {
|
||||
return (Class<T>) self.getClass();
|
||||
}
|
||||
|
||||
public static int compare(long thisVal, long anotherVal) {
|
||||
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
|
||||
|
||||
Reference in New Issue
Block a user