开发者

In Java, are parameters accesses in order when passed into a method?

开发者 https://www.devze.com 2023-03-20 19:23 出处:网络
This is important because I am creating an object out of deserialized primitives within the readObject method.So if I am writing

This is important because I am creating an object out of deserialized primitives within the readObject method. So if I am writing

ObjectInputStream s; //From the readObject method
Object obj = new Object(s.readDouble(), s.readDouble开发者_运维百科(), s.readDouble());

Will it deserialize in the correct order, the order they were written to the byte stream?


Yes parameters will be evaluated in order.


In Java, expressions are always evaluated left-to-right. So the result of the first readDouble call will become the first argument to the Object constructor (but please don't name your class Object! that collides with java.lang.Object), and so on.


Yes, they will deserialize in the correct order.

You might want to create (good) named variables out of those s.readDouble() values though, it's more clear what they mean.


Java argument lists are evaluated Left-to-Right

0

精彩评论

暂无评论...
验证码 换一张
取 消