Hey all,

Just had a thought while looking through the SDE dummy jars.

Anywhere that one uses a construct like this:

public static final int TYPE_SMALLINT = 0;

For example, in SeColumnDefinition.java, I *think* java compiles the 
value of a public static final <primitive> right into the code.  I.e. if 
there were two files like this:

public ClassA {
        public static final int CONSTANT = 0;
}


and

public ClassA {
        public static final int CONSTANT = 1;
}


And one compiled both of these class files into jars, and then compiled 
the following program twice:


package org.depends.on.bad.java;
public ClassAUser {
        public static void main(String[] args) {
                if (ClassA.CONSTANT == 0)
                        System.out.println("ClassA.CONSTANT is Zero");
        }
}


The above "if" statement is calculated at COMPILE-TIME, not runtime, and 
so you'll get a fixed answer, no matter which ClassA you put on the 
classpath.  Here's some sample output:

[EMAIL PROTECTED] compilerTest $ javac -cp classAZERO.jar \ 
ClassAUser.java
[EMAIL PROTECTED] compilerTest $ java -cp classAZERO.jar:. \ ClassAUser
ClassA.CONSTANT is Zero
[EMAIL PROTECTED] compilerTest $ java -cp classAONE.jar:. \ ClassAUser
ClassA.CONSTANT is Zero
[EMAIL PROTECTED] compilerTest $
[EMAIL PROTECTED] compilerTest $
[EMAIL PROTECTED] compilerTest $ javac -cp classAONE.jar \ 
ClassAUser.java
[EMAIL PROTECTED] compilerTest $ java -cp classAZERO.jar:. \ ClassAUser
[EMAIL PROTECTED] compilerTest $ java -cp classAONE.jar:. \ ClassAUser
[EMAIL PROTECTED] compilerTest $


Hmmm...that's bad.  This means that if we don't have the "public static 
final int TYPE_SHAPE" set to exactly the same integer as the SDE API, we 
won't be able to do drop-in replacement.  Things will compile, but 
anything based on a public constant (mostly shape type discovery and 
such) won't work correctly unless one *compiles* the code with the SDE jars.


I wonder if I can get around this by changing the variables from public 
static final to just "public static".

Then we might trick the compiler into not doing compile-time evaluation 
of those constants.

Let me check...

Yes!  It works.

Ok, so I'd suggest that we remove the "final" modifier from all the 
public static constants in the SDE Java API dummy sources.  Otherwise 
stuff won't really work the way we want it to!


--saul

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to