Integer rval = (String)r;这句话不懂亦
#001 public String func(String s, Hashtable ht)
#002 {
#003 …System.out.println( "func invoked "); return s;
#004 }
#005 public static void main(String args[])
#006 {
#007 Class c = Class.forName( "Test ");
#008 Class ptypes[] = new Class[2];
#009 ptypes[0] = Class.forName( "java.lang.String ");
#010 ptypes[1] = Class.forName( "java.util.Hashtable ");
#011 Method m = c.getMethod( "func ",ptypes);
#012 Test obj = new Test();
#013 Object args[] = new Object[2];
#014 arg[0] = new String( "Hello,world ");
#015 arg[1] = null;
#016 Object r = m.invoke(obj, arg);
#017 Integer rval = (String)r;
#018 System.out.println(rval);
#019 }
倒数第二句不懂。r是Object类,是可以强制转化为String类是没错,但是为什么要赋给Integer呢?啥意思啊
------解决方案--------------------我也不懂
------解决方案--------------------写错了吧~~~~
------解决方案--------------------看上下文应该是笔误,应该是
String rval = (String) r;
------解决方案--------------------Integer rval = (String)r;
百分之一千地写错了,这样根本不能编译,哪怕改成 Integer rval = (Integer)r; 都是错的。估计原文的意思是:
String rval = (String)r;