Illegal modifier for parameter ***, only final is permitted"

Source: Internet
Author: User

Hello everyone, I want to define a public variable in the main function. The system reports an error saying "illegal modifier for parameter chatroom, only final is permitted". If public is removed, the compilation is successful. However, even if public is removed, My variable is not final, because I changed it later. Why does the system say it must be final?

Public is used to modify the method or field in the class definition. Another occasion is to modify the class.
Cannot be placed in method.

Only final is permitted
The system means that if you need to add modifiers before the variables in the main function, you can only add final. In this case, your variable is final.

But if you do not add anything before the variable, it is a common variable, not final

Not only in the main method, defining variables in any method cannot declare public,

Public is declared as a domain, and the variables defined inside the method can only be used inside the method (for parameter transfer). The declaration scope is meaningless here, so the declaration is prohibited.

Only final is permitted
Only final is allowed.
This means that the variable can only be declared in the method with final modification as needed. In addition, other modifiers, including static, cannot be used, and the same error will be reported.

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.