4 ms·
1. Records are reference types (heap allocated), structs are not. C# have structs and will also be getting records with 9.0 2. Yes, you can make records of oth
by kasperni 7y ago
1. Records are reference types (heap allocated), structs are not. C# have structs and will also be getting records with 9.0
2. Yes, you can make records of other records.
3. Not yet, but Project Valhalla will be bringing inline types to Java https://wiki.openjdk.java.net/display/valhalla/Main https://wiki.openjdk.java.net/display/valhalla/Main
- skywhopper 7y agoWhat do you mean, "structs are not"? As far as I can tell, structs do not exist in Java?
- kasperni 7y agoStructs in other similar languages, for example, C#
- xxs 7y agoMark Valhalla project has been in the minds of people caring about performance for about 16years now... Struct was a suggested name.
- masklinn 7y agoWhat they mean is that `struct` in GC'd heap oriented languages is generally considered an alias for "a value type", that's what it is in C# or Swift. Records are shortcut syntax (and some runtime improvements) for a specific category of simple classes but they remain a heap-allocated reference type so calling records "struct" would be extremely misleading and would preclude (and / or make even weirder) the eventual inclusion of user-defined value types.
- buckminster 7y agoC# records: https://github.com/dotnet/roslyn/blob/features/records/docs/features/records.md https://github.com/dotnet/roslyn/blob/features/records/docs/... It's a struct or class but you only define the data members and the compiler auto-generates boiler plate like constructors, equality tests, etc.
- xxs 7y agoPersonally I have been wanting to use headerless objects for a long time (pre java7). The best available option is DirectBuffer, still.
- BubRoss 7y agoAren't classes already allocated on the heap? Why would C# need another type like that?
- UK-Al05 7y agoThere low overhead data classes. It's takes a lot create a data class correctly. Including implementing equals, hash etc. Plus a good syntax for creating records. And encourages immutability.
- shawnz 7y agoThe point of both the C# feature and the Java feature is to reduce boilerplate. They are not for improving the performance of apps.
- zamalek 7y agoThe comment is wrong. Records are syntactical sugar for either value or reference types (depending on the language). They simply automatically implement equality, constructors and so forth.