| 
 
| String sex; boolean flag=false;
 }
 class Input implements Runnable
 {
 private Res r;
 Input(){}
 Input(Res r)
 {
 this.r=r;
 }
 
 public void run()
 {
 int x=0;
 while(true)
 {
 synchronized(r)
 {
 if(r.flag)  //??????
 {
 try{r.wait();}catch(Exception e){}
 if(x==0)
 {
 r.name="mike";
 r.sex="man";
 }else
 {
 r.name="丽丽";
 r.sex="女女女女";
 }
 x=(x+1)%2;
 r.flag=true;
 r.notify();
 }
 标红色的地方了没有想明白
 flag的初始值是false.
 为什么写成(r.flag )用来判断是true了。
 
 | 
 |