In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to import static elements into Eclipse. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
How to quickly import Static variables and methods in Eclipse? To be honest, I didn't know before. But today I know that the "Ctrl+Shift+M" (Source > Add Import) shortcut can not only increase missing imports, but can also be used to import static methods and variables in Java programs. Suppose you are using a lot of static variables from a utility class, such as TimeUnit, through the class name, that is, we refer to static variables. In Eclipse IDE, you can fully select the reference variable and press the "Ctrl+Shift+M" shortcut, which automatically imports static elements using static imports in Java.
For example, if you have the following code in your class, as shown in the screenshots of * * Zhang and Chapter 2. You can select TimeUnit.SECONDS and press the shortcut key "Ctrl+Shift+M" to statically introduce the SECONDS variable into your code.
Import java.util.concurrent.TimeUnit; / * * Java Program to show how you can static import some class variables. * * @ author WINDOWS 8 * / public class Test {public static void main (String args []) {System.out.println (TimeUnit.SECONDS); System.out.println (TimeUnit.MINUTES); System.out.println (TimeUnit.DAYS);}}
As shown above, simply mark or select TimeUnit.SECONDS, then press the "type Ctrl+Shift+M" shortcut or select "Add import" from the "Menu" option to introduce static variables from the java.util.TimeUnit class. Repeat this code three times to simplify the above code to the following code, as shown in the fourth screenshot:
Import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; import java.util.concurrent.TimeUnit; / * * Sample program to demonstrate Eclipse shortcut for doing static import. * * @ author WINDOWS 8 * / public class Test {public static void main (String args []) {System.out.println (SECONDS); System.out.println (MINUTES); System.out.println (DAYS);}}
By the way, this feature is not without loopholes. For example, if you do not import the class java.util.concurrent.TimeUnit in advance, then TimeUnit class will be missing. In this case, the "Ctrl+Shift+M" shortcut key has no effect. Only after importing the corresponding class in the code, you need to select the appropriate member and press "Ctrl+Shift+M" to introduce static fields or methods. You can't import all static members with one keystroke. You need to select each of these elements first, and then press the shortcut key as many times as there are static members.
The above is how to import static elements into Eclipse. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.