繁体   English   中英

访问匿名类方法时出现问题

[英]problem in accessing the anonymous class method

我已经编写了这段代码,这在run()方法的行上生成了类似非法表达式开始的错误,请解决我的问题。

     class Reentrant 
        {
            public synchronized void m() 
            {
                 n();  
                    System.out.println("this is m() method");  
                }  


            public synchronized void n() 
            {  
                    System.out.println("this is n() method");  
                }
            {  
                public void run(){  
                        m();//calling method of Reentrant class  
                }  
            };  
        }  
        class ReentrantExample
        {  
            public static void main(String args[])
            {  
                Reentrant re=new Reentrant();  

                Thread t1=new Thread();

                t1.start();  
            }
        } 

更改您的代码,

 { public void run(){ m();//calling method of Reentrant class } }; 

  public void run(){  
                    m();//calling method of Reentrant class  
            }  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM