ObjectInputStream available() method doesn't work as expected (Java)

后端 未结 4 1018
时光说笑
时光说笑 2021-01-07 11:00

I\'ve been trying to figure out why a method I\'ve written to read objects from a file didn\'t work and realized that the available() method of ObjectInputStream gave 0 even

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 11:06

    Although this is not documented clearly I have realized from experience that it has to do with dynamic data. If your class only contains statically typed data, then available() is able to estimate the size. If there are dynamic data in your object, like lists etc, then it is not possible to make that estimation.

提交回复
热议问题