提交 86a62502 authored 作者: Thomas Mueller's avatar Thomas Mueller

Reflection utilities (not sure why "append" fails)

上级 bbef5680
...@@ -11,7 +11,7 @@ import org.h2.test.TestBase; ...@@ -11,7 +11,7 @@ import org.h2.test.TestBase;
import org.h2.util.Utils; import org.h2.util.Utils;
/** /**
* Tests reflection utils. * Tests reflection utilities.
*/ */
public class TestUtils extends TestBase { public class TestUtils extends TestBase {
...@@ -34,12 +34,13 @@ public class TestUtils extends TestBase { ...@@ -34,12 +34,13 @@ public class TestUtils extends TestBase {
long currentTimeMillis1 = System.currentTimeMillis(); long currentTimeMillis1 = System.currentTimeMillis();
long currentTimeMillis2 = (Long) Utils.callStaticMethod("java.lang.System.currentTimeMillis"); long currentTimeMillis2 = (Long) Utils.callStaticMethod("java.lang.System.currentTimeMillis");
assertTrue(currentTimeMillis1 <= currentTimeMillis2); assertTrue(currentTimeMillis1 <= currentTimeMillis2);
// New Instance with Integer parameter (Autoboxing) // New Instance
Object instance = Utils.newInstance("java.lang.StringBuilder", 10); Object instance = Utils.newInstance("java.lang.StringBuilder");
// New Instance with int parameter // New Instance with int parameter
instance = Utils.newInstance("java.lang.StringBuilder", 10); instance = Utils.newInstance("java.lang.StringBuilder", 10);
// Instance methods // Instance methods
Utils.callMethod(instance, "append", "abc"); instance = Utils.newInstance("java.lang.StringBuilder", "abc");
// Instance methods
int length = (Integer) Utils.callMethod(instance, "length"); int length = (Integer) Utils.callMethod(instance, "length");
assertEquals(3, length); assertEquals(3, length);
// Static fields // Static fields
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论