Hi,
One of the many good things to the Luxembourg conference was that it introduced me to Eclipse. I have been looking at some of the plugins I wrote in Eclipse (to clean unused variables, etc) and I noted that when I have imported java.lang.Math.* to use some mathematical functions now (with Java 1.5) this is not needed anymore (same with java.awt.* and some others). Does this mean that the plugins will give an error if run or compiled in IJ with an older Java version? Or is the class fine but the source code incomplete? If so, what is the best way to provide the source code to avoid other people having trouble with the compiling? Leave all the imports? Thanks for any insight. Gabriel |
Hi Gabriel,
To the best of my knowledge, the imports are solely notes for the compiler on where to find classes. The imports should have no effect on the compiled class object. To evaluate your questions, I wrote a little test that includes java.awt.*and then makes reference to some AWT classes. As far as I know, as of Java 1.5, you must still import java.awt when referencing AWT classes (unlike java.lang.*, which is automatically imported). Regarding "import java.lang.Math.*", as far as I know that statement has no effect. I'm not sure it even made sense prior to Java 1.5. The reason that syntax is (close to) valid is because in Java 1.5 you can do static importing ( http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html). For example: import static java.lang.Math.*; and then in your code you can say: int q = log(p); instead of needing to do: int q = Math.log(p); If you are saying instead the Eclipse pointed out that you do not need "import java.awt.*;" in a class where you are actually not using any AWT classes, then of course you do not need to include the import. Hope that helps, and let me know if I have misunderstood your question. -Curtis On 5/25/06, Gabriel Landini <[hidden email]> wrote: > > Hi, > One of the many good things to the Luxembourg conference was that it > introduced me to Eclipse. > I have been looking at some of the plugins I wrote in Eclipse (to clean > unused > variables, etc) and I noted that when I have imported java.lang.Math.* to > use some mathematical functions now (with Java 1.5) this is not needed > anymore (same with java.awt.* and some others). > > Does this mean that the plugins will give an error if run or compiled in > IJ > with an older Java version? Or is the class fine but the source code > incomplete? > If so, what is the best way to provide the source code to avoid other > people > having trouble with the compiling? Leave all the imports? > > Thanks for any insight. > > Gabriel > |
On Thursday 25 May 2006 15:29, Curtis Rueden wrote:
> Regarding "import java.lang.Math.*", as far as I know that statement has no > effect. I'm not sure it even made sense prior to Java 1.5. The reason that > syntax is (close to) valid is because in Java 1.5 you can do static > importing ( > http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html). For > example: > import static java.lang.Math.*; > and then in your code you can say: > int q = log(p); > instead of needing to do: > int q = Math.log(p); Hi Curtis, I see, I thought that I had to import the Math before using Math.atan() and so on. Thanks for clarifying this. > If you are saying instead the Eclipse pointed out that you do not need > "import java.awt.*;" in a class where you are actually not using any AWT > classes, then of course you do not need to include the import. Oops yes my mistake, sorry. Thanks again. Gabriel |
Free forum by Nabble | Edit this page |