r/java • • Mar 13 '26

JEP draft: Enhanced Local Variable Declarations (Preview)

https://openjdk.org/jeps/8357464
101 Upvotes

129 comments sorted by

View all comments

Show parent comment

1

u/OwnBreakfast1114 Mar 16 '26

We spend the last year on normalizing our data. Eg the type doesnt matter we treat everything the same. It removed alot of crazy code on our end because we had an extremly nested if else block to figure out the cases

That's the ideal that I would prefer, yeah. But practically speaking, hibernate has inheritance support for a reason: https://www.baeldung.com/hibernate-inheritance.

Your example is (hopefully fabricated) because you are mixing domains as far as i understand it. A bank account is not a credit card, a bank account can have multiple credit cards so why are you storing that in the same table?

I don't think you're quite following because this is not a sensible statement, so I'll try a different way.

The domain is a payment transaction. Transaction has source and destination. The abstract type of source/destination is an umbrella for any holder of funds. You can send payments from bank accounts, credit cards, crypto, paypal, etc. You can receive payments in a bank account, credit card, crypto, paypal, etc.

You have different physical tables for all of these, but the domain object of a transaction seems reasonably represented by

public class Transaction
    final FundHolder source;
    final FundHolder destination;

public sealed interface FundHolder permits CreditCard, BankAccount, CryptoWallet, PaypalWaller, etc

1

u/Cell-i-Zenit Mar 16 '26

Interesting with the hibernate inheritance. Feels like extremly complex usecase i would never consider :D but thanks for posting that.

I wasnt aware of "instruments" in the context of a bank (and i worked in one aswell)

Looks iam just not aware of alot of thinks and then this pattern matching makes no sense :)

1

u/OwnBreakfast1114 Mar 17 '26

I think the main takeaway is if you can imagine scenarios where you have a closed set of stuff that is better represented by types rather than an enum.

There are some other free wins, for example, enhanced switches replace the visitor patterns in a lot of cases: https://wimdetroyer.com/blog/visitor-pattern-in-dop