Package Private Record Fields
Ty Young
youngty1997 at gmail.com
Mon May 4 06:37:22 UTC 2020
On 5/3/20 3:56 PM, Brian Goetz wrote:
> Making the raw version available by default within the package would
> be a sharp edge on which users would cut themselves over and over.
>
How is this any different then default? One way or the other, unless you
override the default accessor method, you're getting an object that,
while the reference is final, the data it contains might not be. Lists,
Map, Optional, etc all have the same issues. This is something that can
and probably will be overlooked... although IDEs can probably fix this.
Is it expected that everytime such an object is a field of a record that
you need to override the default accessor in order to defensive copy?
Doesn't this violate the "transparent holders" part of records, and
therefore mean that you are trying to use records for something it isn't
designed for?
and for that very same lack of transparency, wouldn't the use of
interfaces, a public one and a private(not exposed, extends the public
one), be better here anyway? For example:
public interface FooPublicInterface
{
public int[] clonedInts();
}
and
public interface FooPrivateInterface extends FooPublicInterface
{
public int[] ints();
}
More information about the amber-dev
mailing list