Sumit Khurana wrote:
declaring a variable transient means that it can't be serialized and static variables are exempted from serialization because serialization is only for instance variables.
I thing,there is no use to declare them together.
There is no relationship between these two variables.if a variable is static than it can't be serialized so,why java allows static with transient???
Stephan van Hulst wrote:Yes, I think the original poster understands that, but he's wondering, why did Java allow it?
Yes, I think the original poster understands that, but he's wondering, why did Java allow it?
Turning the question on its head, how should the compiler handle redundancy ? Throw a compile time error ?
Saying something is static and transient is redundant. Just like saying a variable in an interface is public static final.
I know that static variables can't be serialized and still we can add the transient modifier with it. There is no use of it. it might be redundant. I am just wondering that java allows it. so,there might be some purpose behind this.
not in every case. but might be in this case because you are saying that if serialization occurs than leave this one.but this variable is already out of serialization.
Sumit Khurana wrote:
declaring a variable transient means that it can't be serialized and static variables are exempted from serialization because serialization is only for instance variables.
I thing,there is no use to declare them together.
There is no relationship between these two variables.if a variable is static than it can't be serialized so,why java allows static with transient???
Sumit Khurana wrote:Thanks ranchers now i understood ......it is like declaring a private and final together....
adding static to a variable means you don't want to serialize it....and declaring a variable transient also means the same...but earlier i am thinking in a different way...
Thanks ranchers now i understood ......it is like declaring a private and final together....
adding static to a variable means you don't want to serialize it....and declaring a variable transient also means the same...but earlier i am thinking in a different way...
so if variable is only trainsient : it means it is a non serializable insatnace variable
static transient means: its is non serializable class variable..
private and final are not the same things.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |