MyClass myclass = Class.forName("MyClass").newInstance()

解决方案 »

  1.   

    你这只是生成MyClass的实例,但我需要的是将oOtherObject转换成MyClass而不能通过 
    MyClass myclass = (MyClass)oOtherObject;
    而要通过
    MyClass myclass = ("MyClass")oOtherObject; // 伪代码
    因为oOtherObject具体转换成什么类型需要通过传入的参数决定。
      

  2.   

    用得着吗,可以这样用:if (oOtherObject instanceof Aa) {
        Aa a = (Aa)oOtherObject;
    } else if (oOtherObject instanceof Ba) {
        Ba a = (Ba)oOtherObject;
    }
    根据传入的String参数来决定转换成什么类型是很危险的