Is there cast in Java similar to in C++

后端 未结 7 1037
小蘑菇
小蘑菇 2020-12-04 01:54

I get in my function message array of bytes and type of object, I need to restore object from bytes. Is there in Java any cast like in C++ ?

7条回答
  •  醉话见心
    2020-12-04 02:33

    There is no way in Java to have an arbitrary block of bytes and then tell the compiler "you need to treat this as an object of type X".

    How were those bytes that you want to "restore into an object" created in the first place?

    Java has a serialization mechanism to convert objects to a stream of bytes and vice versa.

提交回复
热议问题