课程
/后端开发
/Java
/深入浅出Java多线程
老师的例子是 Thread actor = new Actor();这个地方我写成 Actor actor = new Actor()行不行?写成前者的好处是什么?求指点,谢谢
2016-06-23
源自:深入浅出Java多线程 2-3
正在回答
也可以用你创建的Actor类来实例化,就像楼上说的,用Thread类实例化等于是向上转型,不会溢出.
写成 Thread actor = new Actor(); 的好处是 直接用 Thread 类对Actor的实例actor进行向上转型,方便后面actor调用Thread类的方法。 你用 Actor actor = new Actor(); 也可以,只是后面再用到Thread的方法时,你还是要把actor转型成Thread。
红袖侍读 提问者
举报
带你一起深入浅出多线程,掌握基础,展望进阶路线
3 回答Thread actor=new Thread(new Actor(),"Mr.Thread");
3 回答Thread actor=new Actor(); 这怎么理解?
4 回答No enclosing instance of type Actor is accessible. Must qualify the allocation with an enclosing instance of type Actor (e.g. x.new A() where x is an instance of Actor).
2 回答怎么我的不行Actor报错
2 回答No enclosing instance of type Actor is accessible. Must qualify the allocation with an enclosing instance of type Actor (e.g. x.new A() where x is an instance of Actor).