implicit constructor translation?
Dan Heidinga
heidinga at redhat.com
Thu Jun 1 14:47:49 UTC 2023
Pulling on a couple of threads to make sure I have the translation strategy
for the implicit constructors straight.
Given a class like Complex with an implicit constructor:
```
value class Complex {
private int re;
private int im;
public implicit Complex();
public Complex(int re, int im) { ... }
...
}
```
and the JEP 401's ImplicitCreation attribute:
```
ImplicitCreation_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 implicit_creation_flags;
}
```
The "obvious" translation is to generate an ImplicitCreation attribute if
there is an implicit constructor, which seems reasonable.
The piece I'm looking for clarification on is whether there will also be a
`method_info` in the classfile representing the implicit constructor.
If the implicit constructor has a `method_info` then it will naturally be
represented in the same way as the explicit `Complex(int, int)`
constructor. This means both will be found by reflective operations (ie by
j.l.Class::getConstructor) without special casing. Users that expect two
constructors will find them in classfile and reflectively.
Alas representing implicit constructors with a `method_info` is not without
costs: primarily specing how the method_info exists and explaining why it
doesn't have a code attribute.
I know this has been mentioned on the EG calls, and I don't recall a final
decision or see it in the spec drafts / documents so far. Was a conclusion
reached on how to do the translation?
--Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-observers/attachments/20230601/1b2837ee/attachment.htm>
More information about the valhalla-spec-observers
mailing list