i have a function
public static Object receviceSigAndData (Socket s) {
byte[] data = null;
try {
DataInputStream din2 = new DataInputStream(s.getInputStream());
int sig_len = 0;
sig_len = din2.readInt();
byte[] sig = new byte[sig_len];
din2.readFully(sig);
int data_len = 0;
data_len = din2.readInt();
data = new byte[data_len];
dsa.update(data);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return (Object)data;
}
the function return an object, if the object is byte array, how do i cast the object to byte[]
?
byte[] b = (?)receviceSigAndData (socket);
thanks
By looking at your code:
Object
: since it's an upcast, it's implicitly done (a byte[]
is statically also an Object
)Object
to a byte[]
by using a specific downcast: byte[] a = (byte[])obj
Object
is completely pointless, signatures are meant to be useful and informative. Returning an Object
is the least informative thing that you can do. If your method is meant to return a byte[]
then its return value should be of byte[]
typeIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With