Our company have developed an accounting program, and it is already near completion.
We developed it with JavaBean and Eclipse in Windows Environment with JRE 1.6.0_05
When we tried to compile and run the program in our linux environment (Server) that runs on 1.4 , the casting error occured..
we have written a program to generate all casting errors that occurred in our project.
import java.math.*;
import java.util.*;
public class testnow {
public static void main(String[] args){
//Declare ALL Primitive!
int TestINT = 150;
Boolean TestBOOL = true;
String TestSTR = "Streng" + "th";
BigDecimal TestDCM = BigDecimal.valueOf(20);
Date TestDATE = new Date();
//Declare ALL Object
Object TestINTObj = 150;
Object TestSTRObj = "Strength";
Object TestDCMObj = BigDecimal.valueOf(20);
Object TestBOOLObj = true;
Object TestDATEObj = new Date();
if(TestINT == (Integer)TestINTObj){
System.out.println("TEST Integer PASSED");
}
if(TestSTR.equals((String)TestSTRObj)){
System.out.println("TEST String PASSED");
}
if(TestDCM.equals(TestDCMObj)){
System.out.println("TEST Decimal PASSED");
}
if(TestBOOL == (Boolean)TestBOOLObj){
System.out.println("TEST Boolean PASSED");
}
if(TestDATE.equals((Date)TestDATEObj)){
System.out.println("TEST Date PASSED");
}
}
}
the following is what happened when i run
javac testnow.java
----------
1. ERROR in testnow.java
(at line 6)
Integer TestINT = 150;
^^^^^^^
Type mismatch: cannot convert from int to Integer
----------
2. ERROR in testnow.java
(at line 7)
Boolean TestBOOL = (Boolean)true;
^^^^^^^^^^^^^
Cannot cast from boolean to Boolean
----------
3. ERROR in testnow.java
(at line 11)
Object TestINTObj = (Object)150;
^^^^^^^^^^^
Cannot cast from int to Object
----------
4. ERROR in testnow.java
(at line 14)
Object TestBOOLObj = true;
^^^^^^^^^^^
Type mismatch: cannot convert from boolean to Object
----------
4 problems (4 errors)
in our windows development JRE 1.6 , it run well and gives the following output :
TEST Integer PASSED
TEST String PASSED
TEST Decimal PASSED
TEST Boolean PASSED
TEST Date PASSED
how do we solve this? i mean we have been using this "convenience" casting all over our code . :(
please help
thanks a lot.
Cheers and God Bless,
Chowi