I am very much a beginner at java programming, and
this my first problem that I have not been able to
resolve via the Sun documentation. Those docs
describe an "import static" construct which would
obviate the need for constantly prefixing, say,
"Math." in front of each occurrence of functions like
abs(), max(), cos(), etc. It does not work for me. I
must be missing something. Eg., why does the
following java program fail to compile?:
______________________________________________________________________
import static java.lang.Math.*;
class TestApp {
public static void main(String[] args) {
System.out.println("abs(-1): " + abs(-1));
}
}
______________________________________________________________________
I believe I was following the advice to be found here:
http://java.sun.com/docs/books/tutorial/java/interpack/staticimport.html
But I get:
______________________________________________________________________
D:\dv\java>javac TestApp.java
TestApp.java:1: <identifier> expected
import static java.lang.Math.*;
^
TestApp.java:1: '.' expected
import static java.lang.Math.*;
^
2 errors
______________________________________________________________________
I installed the SDK using a file named
j2sdk-1_4_2_07-windows-i586-p.exe, which I believe is
current.
Regards,
David V.
Daniel Dyer - 18 Apr 2005 10:28 GMT
> But I get:
> ______________________________________________________________________
[quoted text clipped - 11 lines]
> j2sdk-1_4_2_07-windows-i586-p.exe, which I believe is
> current.
Static imports are new in Java 1.5, you are using 1.4.
Dan.

Signature
Daniel Dyer
http://www.footballpredictions.net
David Vanderschel - 18 Apr 2005 10:43 GMT
> On Mon, 18 Apr 2005 10:24:12 +0100, David Vanderschel <d_vds@hotmail.com>
> > I installed the SDK using a file named
> > j2sdk-1_4_2_07-windows-i586-p.exe, which I believe is
> > current.
> Static imports are new in Java 1.5, you are using 1.4.
I see. I am running Windows 98, and J2SE 5.0 appears
to require Windows 98 SE. :( Anyway, that explains
why the version I downloaded is not the latest after
all.
Thanks for the quick response,
David V.
Chiron Paixos - 18 Apr 2005 10:43 GMT
>I am very much a beginner at java programming, and
>this my first problem that I have not been able to
[quoted text clipped - 3 lines]
>"Math." in front of each occurrence of functions like
>abs(), max(), cos(), etc. It does not work for me.
[...snip...]
>I installed the SDK using a file named
>j2sdk-1_4_2_07-windows-i586-p.exe, which I believe is
>current.
And that is the answer to your question:
the example can be found at
http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html
Now guess what the "j2se/1.5.0" part in this URL means.
Yes it refers to the SDK "J2SE 5.0" (also know as 1.5.0) and there was
no "import static" with any 1.4.x-SDK like the one you installed.
Important rule: Always use the docs and the product with matching
version numbers or you might get into deep trouble, confusion and
sometimes develop suicidal tendencies.

Signature
There are 10 types of people in the world.
Those who understand binary and those who don't.