Accessing the right method in Java

A inner class can call methods of an outer class.

public class Dummy1
{
	private class Dummy2
	{
		public Dummy2()
		{
			method();
		}
	}

	private void method() { }
}

So far so good but if the inner class has the same method this will be called instead. To avoid this ambiguity one can call the method in a more specific way. To be able to call the method of the outer class the prefix Dummy1.this can be added.

public class Dummy1
{
	private class Dummy2
	{
		public Dummy2()
		{
			Dummy1.this.method();
		}

		private void method() { }
	}

	private void method() { }
}
DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare