logoalt Hacker News

torginustoday at 7:55 AM3 repliesview on HN

I know its a faux pas in the Java world to acknowledge the existence of .NET, but how does this differ from .NET structs?

Value types, generic specialization, boxing - a quick skim makes it looks like they picked the same choices.


Replies

DarkNova6today at 11:03 AM

C# actually has a fair amount of gotchas and Java aims to make these explicit. So where C# mostly copied C from a low level perspeCtive, the Java guys approached this high level and analyzed in detail which constraints give you what kind of benefit.

So where in other languages, the struct/class taxonomy is binary, Java allows more granular control, reflection the semantics of the underlying domain. Snd as it turns out, structs have a wide range of footguns, especially in a parallel context.

show 1 reply
_old_dude_today at 8:12 AM

The article has a section about that.

For me, a struct in C/C# can be modified and is passed by copy while a value class can not be modified and is passed by value.

I do not think you can do stack allocation in Java.

show 2 replies
rf15today at 7:59 AM

Functionally they don't - java is just catching up with (by now) ancient practice.

The false dichotomy of

> A struct in C# has identity and mutation, so the semantics of copying on assignment or passing have to be precisely defined, which gives a heavier model for the programmer and less freedom for the runtime.

Doesn't really match with what they're describing. While yes, it will not have identity in a java class ref sense, it of course will still have identity in being a unique structure in memory at a certain address. This is just splitting hairs about Java nomenclature.

show 2 replies