What are the differences between typecasting and data conversion?

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:
Object o = new String("1234");

String myString = (String)o;
This allows you to cast the type of o to it's proper type, String.

Data conversion:

String o = new String("1234");

Integer i = Integer.parseInt(o);
This converts the String "1234" into the Integer which represents the value 1234 (one thousand two hundred twenty four).

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact