What is the purpose of ClassName.this beyond disambiguation?

I've seen ClassName.this used in a lot of Android code on SO and other places online (rather than the simple this keyword) to refer to the current instance of a class. I understand you may decide to preface this with the class name in order to remove any ambiguity, but in my experience doing so is often unnecessary as there can really only be one thing this refers to -- the current instance of the class the code is executing in. Is there something else I'm overlooking that would suggest prefacing the this keyword with a class name is always the better practice, or are there any situations where it is, in fact, necessary?

The Semantic Web: Research and Applications: 8th Extended Semantic , I've seen ClassName.this used in a lot of Android code on SO and other places online (rather than the simple this keyword) to refer to the current instance of a  dcow. Apparently, this user prefers to keep an air of mystery about them. 150. 14 What is the purpose of ClassName.this beyond disambiguation? Mar 29 '13.

there can really only be one thing this refers to.

That is incorrect.

Is there something else I'm overlooking that would suggest prefacing the this keyword with the class name is always the better practice or are there any situations where it is necessary?

Yes and yes, respectively. In particular, ClassName.this is needed from inner classes to get to the outer class instance of this.

For example:

  myButton.setOnClickListener(new Button.OnClickListener() {  
    public void onClick(View v) {
          startActivity(new Intent(MyActivity.this, MyOtherActivity.class));
        }
     });

Here, using this instead of MyActivity.this will fail with a compile error, complaining that Button.OnClickListener is not a valid first parameter to the Intent constructor. MyActivity.this returns the this that is the MyActivity instance that encloses the Button.OnClickListener instance.

Information Technology, Finally, we applied the heuristics beyond the boundary of the blocks for GeoNames classes with WordNet by disambiguating their meaning manually [14]​. ontology, check if the corresponding class name is available in GeoWordNet. A disambiguation page should not be made up completely of red links or have only one blue link on the entire page, because the basic purpose of disambiguation is to refer users to other Wikipedia pages.

I don't have that much repo to put a comment ,so writing it down as an answer.

I think the basic concern of the question was to check if there exists any advantage of using classname.this over 'this' keyword in scenarios where developer already know that there will not be any inner class call.

Of course in case of inner class scenarios ,you have to use classname.this to call its enclosing class. but there can be scenraio that you already know that this particular code won't be called inside any inner class.so why to specify classname.this,instead just use 'this'.

How should I get started on writing device drivers?, Unlike other and older methods of classification, neural networks function as both input data and solve problems beyond those that are only linearly separable [5]​. document filtering, metadata generation, word sense disambiguation, and in Each node from the tree contains either a class name (leaf node) or contains  In Beyond Good and Evil, Nietzsche accuses past philosophers of lacking critical sense and blindly accepting dogmatic premises in their consideration of morality. Specifically, he accuses them of founding grand metaphysical systems upon the faith that the good man is the opposite of the evil man, rather than just a different expression of the same basic impulses that find more direct expression in the evil man.

Window win = SwingUtilities.getWindowAncestor(RedPanel.this);

Usually you'll see code like this inside of an inner class. So say you have a class called RedPanel that subclasses a JPanel, and say inside of this you have an anonymous inner class that implements ActionListener. If you want to refer to the "this" RedPanel object inside of the ActionListener, you can't use just "this" since it refers to the ActionListener not to RedPanel. To get a handle on the RedPanel "this" you'll need to use RedPanel.this.

Java (disambiguation), 14 What is the purpose of ClassName.this beyond disambiguation? Mar 29 '13. 13 Can a custom View know that onPause has been called? Mar 13 '14. View all​  This disambiguation purpose is most obvious when a message possesses verbal information about affect. Walther and D'Addario (2001) gave participants messages that were ostensibly from a friend and asked them to rate the messages. The researchers found that the addition of an emoticon to a message that was the same valence (e.g., a smiley face added to a positive message, or a frowny face added to a negative message) did not reliably affect the ratings of the message's affect.

Chapter 8. Classes, I use a Mac OS X Macbook, but I also have an Ubuntu machine (running on a Mac Min). What is the purpose of ClassName.this beyond disambiguation? This article is a disambiguation page for Tactics The following is a list of links to pages that might share the same title. Please follow one of the disambiguation links below or search to find the page you were looking for if it is not listed. If an internal link led you here, you may wish to change the link to point directly to the intended article. "Tactics" may refer to: The Tactics skill

Intent, Java is an island of Indonesia. Java may also refer to: Contents. 1 Computing; 2 Geography By using this site, you agree to the Terms of Use and Privacy Policy​. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.,  The 'jigger' or short-rest used in billiards is also often called a 'gadget'; and the name has been applied by local platelayers to the 'gauge' used to test the accuracy of their work. In fact, to borrow from present-day Army slang, 'gadget' is applied to 'any old thing.' The usage of the term in military parlance extended beyond the navy.

Class declarations define new reference types and describe how they are The type parameter section follows the class name and is delimited by angle brackets​. since they are used in different contexts and are disambiguated by different is not accessible outside the class Point , even through a superclass constructor  This disambiguation page lists articles associated with the same title. If an internal link led you here, you may wish to change the link to point directly to the intended article. This page was last edited on 15 February 2020, at 14:19. Content is available under CC BY-NC-SA 3.0 unless otherwise noted. Game content and materials are trademarks

Comments
  • Can you not do so by omitting EnclosingClass.this and simply calling someMethod()?
  • Not if someMethod() exists in the inner class too.
  • @EtienneMiret +1 agreed.
  • @EtienneMiret well yes. But then we digress to the scenario where the prefix is only used to remove ambiguity. I think CommonsWare raises the point that EnclosingClass.this is the only way to refer to the instance of an enclosing class from an inner or anonymous class.
  • It's equivalent to self.someMethod() in swift
  • Thanks. I figured this may be the case but I've seen it used beyond referring to an enclosing class from an inner or anonymous class so I felt compelled to query SO.
  • @DavidCowden: Sometimes you will see it from code that had been in an inner class, got refactored out of the inner class, but the developer left the class name qualifier on there, as it did not raise a compile error and they didn't elect to remove it. There are probably some developers who like using it just for clarity's sake.
  • Yeah, that makes sense. Also, I would accept both these answers but I can't so I'll throw some extra rep @Eng.Fouad 's way since they have at least one order of magnitude (in base 10) less than you in the rep department (=
  • Well the way I read the answers was that this was the only reason. So to answer your comment, there is no reason other than to reference shadowed objects. (Unless you're considering code style preferences, etc.)