提交 a3f636b5 authored 作者: Thomas Mueller's avatar Thomas Mueller

Reflection utilities (workaround for JDK bug)

上级 c7cc0888
...@@ -38,11 +38,12 @@ public class TestUtils extends TestBase { ...@@ -38,11 +38,12 @@ public class TestUtils extends TestBase {
Object instance = Utils.newInstance("java.lang.StringBuilder"); 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);
// StringBuilder.append or length don't work on JDK 5 due to
// http://bugs.sun.com/view_bug.do?bug_id=4283544
instance = Utils.newInstance("java.lang.Integer", 10);
// Instance methods // Instance methods
instance = Utils.newInstance("java.lang.StringBuilder", "abc"); long x = (Long) Utils.callMethod(instance, "longValue");
// Instance methods assertEquals(10, x);
int length = (Integer) Utils.callMethod(instance, "length");
assertEquals(3, length);
// Static fields // Static fields
String pathSeparator = (String) Utils.getStaticField("java.io.File.pathSeparator"); String pathSeparator = (String) Utils.getStaticField("java.io.File.pathSeparator");
assertEquals(File.pathSeparator, pathSeparator); assertEquals(File.pathSeparator, pathSeparator);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论