News for hackers. Stuff that matters.
Re:Data Classes for Java by alkonaut on Thursday November 02, 2017 @04:51AM (#15608791)
Then that is when you have to change the public field to a property, with no change to calling code.

Reasons for going with a property from the start is if you a) ever use reflection (which would need to change depending on whether the storage is a public field vs a property) b) If you need to implement interfaces using the property. Reasons for going with a public field is for special cases where you know a lot about how inlining affects your performance. Typically in structs.

Since there is no more boilerplate used to write "public int Id { get; }" vs "public readonly int Id", in 99% of cases I'd choose the latter.

There are no comments on this comment yet.