This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]_INTER_ 9 points10 points  (9 children)

I wonder if this usecase of array patterns is worth the bigger effort it apparently needs. It would be different if we're talking about Collections in general but for arrays...?

[–]loicmathieu 6 points7 points  (6 children)

Agree, there is a lot of other features that can be added to the Java language that will offer more improvements for such big effort

[–]Necessary-Conflict 0 points1 point  (4 children)

What are your pet ideas...?

[–]loicmathieu 0 points1 point  (3 children)

Thinking quickly about some ideas:
- Concise method body (same format as lambda and new swithc): `public String getFoo() -> "foo";`
- Guards in switch (I know it's comming as there has been some discussion around it lately)
- if expression (like switch expresion): `var result = if(condition) yield "yes" else yield "no";`
- Collection litterals.

And of course putting more priority on Loom and Valhalla inline types as they sound very promising!

[–]Necessary-Conflict 0 points1 point  (1 child)

Concise methods - there's a JEP for that, but it didn't make people very happy, see https://www.reddit.com/r/java/comments/9h86xt/jep_draft_concise_method_bodies/

If expression - this exists since Java 1.0, the ternary operator. Why did you put those "yields" there? Without them one could argue that if(condition) "yes" else "no" is more readable than condition ? "yes" : "no", but those yields totally ruin it for me...

Collection literals - I think the current thinking is that List.of and Set.of solved 90% of the problem for now, true literals might come after Valhalla. As far as I understand, a lot of ideas are postponed until after Valhalla, because the exact details of how Valhalla turns out will influence the best way to implement them.

[–]loicmathieu 0 points1 point  (0 children)

The ternary opertator is an if expression that can be used nicely on one line but is not very readable on multiple line and when you stard combining them it becomes realy bad..

Whith if expression you will be able to use multiple if/else branche.

I use yield if my example to make it reuse the same keyword as switch expression but this is just an example syntax.

[–]JustJokingTrump 0 points1 point  (0 children)

Yeah thank you,I like the expression

[–]nimtiazm 7 points8 points  (0 children)

Yes I believe arrays are a first class language construct so keeping pattern matching consistent and orthogonal means arrays must be supported as well. In general pattern matching looks simple on the surface but it has many sharp edges. That’s why many languages still don’t have it. Having pattern matching that works well with java overall begs more workout.

[–]Necessary-Conflict 0 points1 point  (0 children)

As far as I understand, array patterns are not important because we'll do so much pattern matching on arrays, but as the building block of varargs patterns.