[lworld] RFR: 8279656: [lworld] Javac diagnostic compiler.err.primitive.class.must.not.implement.cloneable not valid anymore
Srikanth Adayapalam
sadayapalam at openjdk.java.net
Mon Jan 17 09:44:02 UTC 2022
On Sat, 15 Jan 2022 09:26:08 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:
>> Elides the restriction for `Cloneable`.
>
> test/langtools/tools/javac/valhalla/lworld-values/T8279656.java line 11:
>
>> 9: primitive class Primitive implements Cloneable {
>> 10: }
>> 11: }
>
> First I thought we may need a similar test in value-objects directory since value objects will get integrated ahead of and independently of primitive classes - but value objects are new and so were never restricted in the first place - so perhaps we don't need a test there after all.
According to the javadoc on Cloneable:
By convention, classes that implement this interface should override
* {@code Object.clone} (which is protected) with a public method.
* See {@link java.lang.Object#clone()} for details on overriding this
* method.
But elsewhere we forbid clone from being overridden in a primitive/value class - that restriction should be co-lifted.
ATM if I compile
primitive class X implements Cloneable {
public X clone() {
throw new Error("Not implemented yet");
}
}
it results in
X.java:2: error: value classes may not override the method clone from Object
public X clone() {
^
1 error
-------------
PR: https://git.openjdk.java.net/valhalla/pull/603
More information about the valhalla-dev
mailing list