serialization - Casting Character to char and char to Character Java -


can please explain me why code working fine?

import java.io.*;  public class array {     public static void main(string[] args) throws ioexception, classnotfoundexception {         fileoutputstream fo=new fileoutputstream("character.dat");         objectoutputstream oos=new objectoutputstream(fo);         fileinputstream fi=new fileinputstream("character.dat");         objectinputstream ois=new objectinputstream(fi);         character c = 'h';         oos.writeobject(c);         character arr = (char)ois.readobject();         system.out.println(arr);         fo.close();         fi.close();         oos.close();         ois.close();     } } 

in line 10, have created character , have serialized in line 11 , written file. in line 12, have deserialized object, returns reference of object, have downcast character. in line 12, downcasting char (which primitive data type , not class) , still working fine. why that?

i think cast object char , assignment character still working because of java's autoboxing going on behind scenes. link might explain more in depth.


Comments

Popular posts from this blog

What Are The Best Universities In The World?

The Ten Most Livable Cities In The World

Hard vs. Soft Water: What's The Difference?