What are the differences between typecasting and data conversion?
Created May 8, 2012
Christopher Schultz TypeCasting is a feature of the language whereby you are telling the compiler (and readers of your source code :-) that you explicitly want it to treat the object as if it were really of the type that you specified rather than it's actual type.
Data conversion is physically changing one chunk of data into another, often with interpretation.
The difference can be illustrated thus:
Typecasting:
This allows you to cast the type ofObject o = new String("1234"); String myString = (String)o;
o
to it's proper type, String
.Data conversion:
This converts theString o = new String("1234"); Integer i = Integer.parseInt(o);
String
"1234" into the Integer which represents the value 1234 (one thousand two hundred twenty four).