I have a small java file given below.
class abc{
public static void main(String args[]){
Object a= 9;
int b= (int)a;
System.out.print(b);
}
}
It gives error while compiling in cmd but not in Netbeans. Also, when I replace '(int)a' with '(Integer)a', it compiles and runs fine on both cmd and Netbeans.
class abc{
public static void main(String args[]){
Object a= 9;
int b= (Integer)a;
System.out.print(b);
}
}
What is the reason for this and how can I fix this?
EDIT: The error that shows up while compiling the first code is:
C:\Users\ANKIT.ANKITSHUBHAM-PC>javac abc.java
abc.java:4: inconvertible types
found : java.lang.Object
required: int
int b= (int)a;
^
1 error
EDIT: This question is not about casting. It is about why cmd and Netbeans behave differently when I cast object into int using '(int)' but behave in a same way when cast using'(Integer)'.