What is the difference between the Java class name and the class name.

Source: Internet
Author: User

The syntax for the "class name. This" is called "qualified this" in the Java language. The relevant provisions are here: Chapter 15. Expressions-qualified this
The main purpose of this syntax is to use the outer class name. This syntax when you want to specify the "this" reference for a perimeter class of a nested hierarchy in the method of the inner class. For example, say:
class Foo {  class Bar { Foo getFoo() { return Foo.this; } }}

In the Getfoo () method of the Foo.bar class, if you write "This" directly, it refers to an instance of the Foo.bar class, and if you want to specify the this instance of the Outer Foo class, it is written in Foo.this.
In particular, if you write Bar.this in the Getfoo () method of the previous example, the function is the same as writing this directly, specifying the current instance of the Foo.bar class.



Rednaxelafx
Links: https://www.zhihu.com/question/55565290/answer/145355951
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

What is the difference between the Java class name and the class name.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.