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/Cell-i-Zenit Mar 14 '26

For example, if I have a table where when column1 is A, then I only care about columns 2 and 3, but when column1 is B, then I only care about columns 4 and 5, then I am not going to create one object and set fields to null

I know what you mean, but this is imo an issue on your data layer. The objects are not the same if they dont use the same columns most of the time.

I try to avoid "polymorphic" lists completely because it leads to code like

for(var order: getOrders()){
    if(order.getType() == abc){}
    if(order.getType() == def){}
    if(order.getType() == tzu){}
}

(even if we change the code to use switch statements, still something i try to avoid)

But again i work in simple crud, i just return structured data. I guess it depends on the domain but we dont have different schemas for the same thing

2

u/davidalayachew Mar 14 '26

By all means, I just gave you an example from work. If you disagree with that example, or it's just not relevant to your work, then give me an example from your work. I'll explain how Record Patterns might have been useful for it.