简体   繁体   English

Java进口是否专业使用?

[英]Are java imports used professionally?

I'm currently self studying Java, and am not sure with this "import" thing. 我目前正在自学Java,不确定是否要使用“导入”功能。 It adds classes(not sure), and has methods that would serve a different function relative on the type of class I declare from the "import"ed thing. 它添加了类(不确定),并具有相对于我从“导入”事物中声明的类的类型提供相对不同功能的方法。

I'm curious if import is frequently used for work, or is this relative to the user if he/she would want to use import or not. 我很好奇导入是否经常用于工作,或者这是否相对于用户(如果他/她是否要使用导入)。

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner ThisObject = new Scanner(System.in);
    }
    }

Java import is a compile time feature that allows you to omit the package name when programming. Java import是一种编译时功能,可让您在编程时省略软件包名称。 There is no byte-code import , the compiler will replace 没有字节码import ,编译器将替换

Scanner ThisObject = new Scanner(System.in);

with

java.util.Scanner ThisObject = new java.util.Scanner(System.in);

As for how common it is, I would say extremely . 至于它有多普遍,我会说得非常多 However, there is another form of import called static import which allows you to bring static methods and fields from another class into your current namespace . 但是,还有另一种称为static importimport形式,它允许您将来自另一个类的static方法和字段带入当前的名称空间 static import is not very common . static import不是很常见 Finally, Java variable names start with a lower case letter (by convention). 最后,Java变量名称以小写字母开头(按照惯例)。

import static java.lang.System.in;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner thisObject = new Scanner(in); // System.in through static import
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM