public interface XActionForm
{}
///////////////////////////////////////
XActionForm xActionForm = new XActionForm();YActionForm yActionForm = YActionForm.class.cast(xActionForm);请问这段代码如何理解,我参考了JDK文档,但是还是不懂!请高手解答!

解决方案 »

  1.   

    cast
    public T cast(Object obj)将一个对象强制转换成此 Class 对象所表示的类或接口。 public class Main {
        public static void main(String[] args) {
            RefInterface test = new TestCast();
            TestCast test2 = TestCast.class.cast(test);
            try {
                Main m = Main.class.cast(test);
            } catch (ClassCastException e) {
                System.out.println("非法转换");
            }
        }
    }interface RefInterface{}class TestCast implements RefInterface{}