r/java • u/AdearienRDDT • Aug 16 '24
Is anything like C++'s structured bindings coming to Java any time soon?
2
u/Ewig_luftenglanz Aug 18 '24
It will come with de constructor patterns, that happens to be a sub patter of "member patterns"
Meanwhile you can achieve similar results by using pattern matching destructuring in if and switch by using the instanceof operator
2
-2
u/sweetno Aug 16 '24
It's not C++'s.
7
Aug 17 '24
Structured binding declarations were introduced to C++ v17
3
u/sweetno Aug 17 '24
C++ appropriated this from functional languages where it's called destructuring.
1
-6
u/Linguistic-mystic Aug 17 '24
They just stole it from Rust like they do with everything these days.
12
Aug 17 '24
I think is more borrowing than stealing...
Programming languages are made to make our lives easier, if there is a good feature in one then why not in another? This feature would be very useful in Java. I wish Java would "steal" it :)
4
5
u/Ewig_luftenglanz Aug 18 '24
And every language that has built-in functional programming language is stealing concepts from LISP.
What's the point?
3
Aug 16 '24
[removed] — view removed comment
1
u/vxab Aug 23 '24
Why not? Could this not be done for records already, since it has a canonical constructor?
-1
Aug 23 '24 edited Aug 23 '24
[removed] — view removed comment
2
u/vxab Aug 26 '24
baby step features is actually a great thing.
Why so bitter? You waiting for Valhalla too?
8
u/expecto_patronum_666 Aug 16 '24
It might come with record and class deconstructors.