Eclipse code format: "{}" format setting

Source: Internet
Author: User

Eclipse Sets the format of the code curly braces

There are many styles of writing code, common in three styles:

1, K & R style: This style of code is relatively compact, the advantage is in textbooks or printed into paper when compared to the provincial place; The disadvantage is the brace matching problem, the code is large, it is not good to find the last parenthesis position, can only be marked by post-comment

 Public class Test {    publicstaticvoid  main (String args[])        }}

2, the standard style (BSD style): This style of display code is relatively loose, the advantages are hierarchical, written code is easy to read, the disadvantage is: waste space, especially when printing code

 Public class test{    publicstaticvoid  main (String args[])    {        }}

3, GNU style: This style originated from GNU, all GNU Software Foundation adopted this style, the advantages and disadvantages of the same as the BSD style, characterized by parentheses before and after the empty two lattice.

 Public class Test  {    publicstaticvoid  main (String args[])      {          }  } 

I personally prefer the standard BSD style, because the code is clearly structured, concise and easy to read, and Eclipse can customize the code style by setting the following method:

1, open eclipse,window menu, preferences option;

2. Find the Java-->code style-->formatter (java--> code style--format) setting, New one format. The default format of Eclipse is not allowed even if you edit the change.

3, so we want to create a new format of our own. As you can see from the previous figure, I've got the name Mybracesoption (because I changed the format of the curly braces, so I got the name). Here for demonstration, I re-created a new format, re-named MyEclipse;

4, braces is to change the format of curly braces, the following heap drop-down menu is the code in different locations of the curly brace format, you can try it yourself. If you and I like the standard style, then recommend you in addition to the penultimate array initializer: Same line, the rest of the choice: Next line. After that, always OK, the setup is complete. You can see that the format has changed when you edit the code.

Eclipse code format: "{}" format setting

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.