Named parameters in data classes
Pablo Grisafi
pablogrisafi1975 at gmail.com
Thu Nov 30 16:40:10 UTC 2017
I don't know if this was already discussed, but it will be nice to
have named parameters on data classes. I see a future with things like
datum class Charges(
BigDecimal gross;
BigDecimal stateTaxes;
BigDecimal federalTaxes;
BigDecimal discount;
)
become common, it will be really less error prone to write (and more
clear to read)
var charges = new Charges(gross = a, stateTaxes = b, federalTaxes =
c,discount = BigDecimal.ONE)
instead of
var charges = new Charges(a, b, c,BigDecimal.ONE)
I think (but I may be wrong) the main issue with named parameters is
that they don't play well with inheritance, but since data classes
will not have inheritance, it could be possible in this case
Also, default values would also be nice to have
datum class Charges(
BigDecimal gross;
BigDecimal stateTaxes;
BigDecimal federalTaxes;
BigDecimal discount = BigDecimal.ONE;
)
and then
var charges = new Charges(gross = a, stateTaxes = b, federalTaxes = c)
Pablo Grisafi
pablogrisafi1975 at gmail.com
More information about the amber-spec-comments
mailing list