Throwing exceptions from records
Ty Young
youngty1997 at gmail.com
Thu Mar 5 19:12:43 UTC 2020
Actually going to expand this a bit after messing around with records...
How is records supposed to work beyond the most basic usage of Point(int
x, int y)? There isn't much information out there for the more advanced
usages so I'm confused.
To go into more detail, I'm trying to convert this:
https://github.com/BlueGoliath/Goliath-Nvidia-Bindings/blob/master/modules/org.goliath.bindings.nvml/src/main/java/org/goliath/bindings/nvml/functions/nvmlInit.java
which doesn't seem possible as-is because you can't throw exceptions
from record constructors.
Furthermore there seems to be some constraint where constructor
arguments have to match the record argument signature. Why does that
even matter?
As a result, I can't convert classes like:
https://github.com/BlueGoliath/Crosspoint/blob/master/src/main/java/org/goliath/crosspoint/unions/BasicNativeUnion.java
to a record.
On 3/5/20 11:16 AM, Alex Buckley wrote:
> Per JEP 359, the list for record-related discussion is amber-dev.
> bcc'ing jdk-dev off this thread.
>
> On 3/5/2020 9:12 AM, Ty Young wrote:
>> Hi,
>>
>>
>> Is there a way in JDK 14 records to throw exceptions from a
>> constructor? Currently I have dozens of classes that I want to
>> convert to records but am unable to due to there being no way to have
>> a constructor that throws exceptions. I'm not able to find any
>> examples of how records and exceptions are supposed to work together
>> online either...
More information about the amber-dev
mailing list