interface Person
{
abstract void show();
}
class Student implements Person
{
public void show()
{
System.out.println("student run");
}
}
class ProxyStudent implements Person
{
private Student s;
public void show()
{
before();
if(s == null)//这个比较是什么意思,为什么不直接new一个Student对象呢?
{
s = new Student();
}
s.show();
after();
}
public void before()
{
System.out.println("do something before show");
}
public void after()
{
System.out.println("do something after show");
}
}
public class ProxyDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
ProxyStudent ps = new ProxyStudent();
ps.show();
}
}
请教各位高手,s==null是说明意思,为什么要进行这个比较,为什么改成s!=null 就提示空指针异常了,知道的详细解答一下,不胜感激
|
|