java import problem
迷茫
迷茫 2017-05-17 09:59:25
0
1
485

import java.lang.System.out;//error
Why is the above statement at the beginning of the program wrong?
The following sentence is correct regardless of whether it has static or not. Why is this?
import static java.lang.System.*;

as the picture shows:

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
阿神

First you need to understand the newly added feature in 1.5 called static import
The so-called static import simply means importing static variables and methods

The format is import static package name.class name.static property|static method

Let me show you the source code: out is a static variable modified with static, so if you don’t add static when importing the package, an error will be reported
The System class only has static-modified properties or methods, so you don’t need to add static.

public final static PrintStream out = null;

   
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!