Looking For Anything Specific?

ads header

static import java good or bad

 


usually, we can access static member by using the class name but wherever we have written static import we can access static members directly without the class name.


usage of static import reduces the length of code and increases the readability. according to worldwide programming, experts says that static import create confusion and reduces readability 


Hence there is no specific requirement it's not recommended to use static import 




Normal import

Explicit import

Syntax 

import packagename.classname;

example
import java.util.ArrayList;

Implicit import

Syntax 

import packagename.*;

example
import java.util.*;


static import

Explicit import

Syntax 

import static packagename.classname.staticmemeber;

example
import java.lang.Math.sqrt;
import java.lang,System.out;

Implicit import

Syntax 

import static packagename.classname.*;

example
import static .java.lang.Math.*;



out is static variable present in a System class,hence we can access by using class name System.but wherever we w\are writing static import it's not required to use the class name we can access out directly.

Post a Comment

0 Comments