I have always had a question about java.lang.Math: (It might by very basic)
Why do I have to Math.abs(-100)
and can't to abs(-100)
?
I figure that Math
is a class. And abs
is a static method. But why can I not simply import java.lang.Math
and use abs(-100)
?
You can import all the methods in Math
:
import static java.lang.Math.*;
or just the one method you want:
import static java.lang.Math.abs;
Normal imports just import classes, making that class available via its short name.
See more on this question at Stackoverflow