Sunday, July 5, 2009

static import statements

We usually add an import statement as import java.util.List;

but there is also static import statements like

import static java.lang.Math.*;

Use :-

in java when we use Math class to use methods as Math.sqrt(), Math.pow(x, a);

because all methods in Math class are static, we can make a static import as

import static java.lang.Math.*;

and can access methods as

double value = sqrt(4);

System.out.println (value); // gives 2.0

No comments:

Post a Comment