In Java, are parameters accesses in order when passed into a method?
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
精彩评论