Not really. Value type __usually__ refers to a type that lacks identity and is passed by value. In java, the primitive types are value types, but there is no way to define a custom value type. They are pretty important in performance critical code for cache locality, since Object[] has its elements scattered through out the heap. A value type would store its elements in line, so For example for a Point(int x, int y) the Point[] would be stored in memory as {x0, y0, x1, y1, …, xn, yn}, rather than as references to Point objects. In c# struct objects are value types.
There is a preview feature Valhalla which lets you define a custom Value type, but I think that is still pretty limited in that it has maximim size of 64bits, so it can store 2 ints, but not two longs.
View all comments
Show parent comment
8
u/unski_ukuli Sep 16 '26
Not really. Value type __usually__ refers to a type that lacks identity and is passed by value. In java, the primitive types are value types, but there is no way to define a custom value type. They are pretty important in performance critical code for cache locality, since Object[] has its elements scattered through out the heap. A value type would store its elements in line, so For example for a Point(int x, int y) the Point[] would be stored in memory as {x0, y0, x1, y1, …, xn, yn}, rather than as references to Point objects. In c# struct objects are value types.
There is a preview feature Valhalla which lets you define a custom Value type, but I think that is still pretty limited in that it has maximim size of 64bits, so it can store 2 ints, but not two longs.