Coming soon: Stream.toList()
https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-November/070782.html21
u/talios Nov 03 '20
As much as I didn't like collectors initially I do like the abstraction and not baking it onto stream ( does this mean we should also add toSet as well?
I'd much rather see a Streamable interface that has the stream() call on it - then flstMap() usage would cleaner without slapping stream() calls everywhere.
5
5
u/kuemmel234 Nov 03 '20
If you have a look on the post itself, they write that List is special.
From the use perspective I kind of agree, though. Also toMap, then you would have all the important collections on stream and collectors remain for special use cases (while it takes some time getting used to, there are a few cases where writing my own collector came in pretty handy).
3
u/Yithar Nov 03 '20
Yeah, I really like the Traversable trait in Scala, which defines the contract for
map(),flatMap(),filter(),reduce(), etc. I wonder if it has something to do with the contracts that we have to get aStreamtype and deal with that and then normally useCollectors.toList().On a side note, I happened to come across this StackOverflow answer which criticizes certain aspects of the Stream API:
Java's Stream API is focused on the performance of bulk operations on large data structures. It also offers auto-parallelization towards the same goal (although it almost never actually helps), but its API is crippled and at times awkward due to these concerns. For example, many useful operations which don't happen to parallelize well are just not there, and the whole paradigm of non-terminal vs. terminal operations adds bulk to each and every Streams expression you write.
20
15
12
8
u/Dokiace Nov 03 '20
It is exciting but I think I'm gonna have to stay on Java 8 forever
13
u/nutrecht Nov 03 '20
Curious; why? Staying on an ancient version is a pretty big risk for a company.
8
u/Dokiace Nov 03 '20
I wholeheartedly agree with you but apparently I'm not expert enough to weigh in on this decision, and those tech leads deem upgrading is unnecessary
10
u/nutrecht Nov 03 '20
Some awesome 'tech leads' you have there. Let me guess, it's part of the typical 'career' path where the spots are basically reserved for people who've been around at the company for a long time? :)
8
u/Dokiace Nov 03 '20
Well those tech leads do have a long tenure on the company, hmm I think you're onto something here. 😜
2
u/nutrecht Nov 04 '20
Often these people simply don't recognize the risks of outdated stacks, or worse, use it as a way to make themselves indispensable. The longer you stick to 8, the harder it will be to hire good developers.
2
u/thephotoman Nov 03 '20
They could be stuck like me: I have an app that is stuck on Java 8. That's the latest version that a third party dependency supports. Putting it into later versions does not work.
No, it's not technical debt. It fills a very niche role, and no matter which vendor we choose, this is a particular task that will always lag by a few years.
IBM is the vendor. You're pretty much up against a wall and locked in with them.
3
u/nutrecht Nov 04 '20
While I do appreciate that this is far from a simple issue to fix, I don't understand how you define this as "not technical debt". Being blocked on stuff because of outdated 'stuff' (IBM in this regard) is IMHO textbook technical debt.
This does not mean it has to be fixed; it could simply be that the benefits won't ever outweigh the costs. But the person I responded with said they're stuck on 8 forever. Not that they had a single application that's stuck with outdated dependencies.
If your entire stack is stuck on 8 forever this is a massive risk to the company just for the simple reason of not being able to hire Java developers in a while.
1
u/Dokiace Nov 04 '20
Nope, luckily my orgs dont have that kind of problem, we mainly use Spring Boot
2
u/thephotoman Nov 04 '20
Oh, we do too.
It's just that for this one specific job, the existing tools really suck. It's not something that people tend to use Java for if we're all being honest with ourselves. Usually this stuff gets done in C++, but the rest of the project is in Java, nobody wants to do it in C++, and as a result, we're stuck with an external tool that kinda sucks.
0
Nov 04 '20
[deleted]
1
u/Muoniurn Dec 18 '20
More often than not these corps don’t even buy support they just assume that it is LTS and it will forever get security patches for free - which is not the case with any jdk release
11
4
2
u/Clitaurius Nov 03 '20
Is it clear that it is to an existing List implementation?
5
u/Me4502 Nov 03 '20
Looking at the javadocs, it specifies it makes no guarantees about any property of the list (mutability, etc). So by spec I don’t believe it needs to be a specific existing List implementation.
If that control is needed, it recommends using the existing collect method.
2
2
Nov 03 '20
So, if this method goes live would it further discard the possibility of a new Collections interface framework?
I mean, creating a new one is probably a very bad idea for several reasons, but there are some gripes I have with the current and these good news are a bit sour.
3
u/kaperni Nov 03 '20
What gripes could you have? That could possibly offset the pain of introducing a completely new collection framework. And having a decade long transition to it.
3
Nov 03 '20
Gripes like optional operations with methods that enable mutability by default, usage of null and exceptions, lack of integration with Optional, and the sorts.
I understand the heavy drawbacks of creating a whole new Collections framework and that some of these can be aliviated by using difference interfaces (Iterable instead of Collection) or by new default methods (Map::getOptional), but even so it'd be something I'd like to see.
Even creating a new one might not be a good solution (see Scala's collection framework and the headaches of the Mutable/Immutable separation).
1
1
-15
60
u/efge Nov 03 '20
As pointed out by Stuart Marks and John Rose, it's more than just a convenience method, as it allows notable optimizations and ties into the Valhalla story. https://bugs.openjdk.java.net/browse/JDK-8180352?focusedCommentId=14133065&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14133065