内部类访问外部类方法,方法名称相同 [英] inner class access to outer class method, same method names

查看:104
本文介绍了内部类访问外部类方法,方法名称相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类和一个子类

01 public class A{
02   void test(){};
03   public class B{
04     void test(){
05       test();
06     }
07   }
08 }

好的,在第05行id喜欢访问类A的方法测试。
但我进入循环因为我不知道如何指定使用类A的方法。

Ok, in line 05 id like to access the method test of class A. But i go into a loop because i dont know how to specify to use the method of class A.

任何想法?

推荐答案

01 public class A{
02   void test(){};
03   public class B{
04     void test(){
05       test();  // local B.test() method, so recursion, use A.this.test();
06     }
07   }
08 }

编辑:As @Thilo提到:避免在外部类和内部类中使用相同的方法名称,这样可以避免命名冲突。

EDIT : As @Thilo mentioned : Avoid using same method names in outer class and inner class, this will avoid naming conflicts.

这篇关于内部类访问外部类方法,方法名称相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆