danceboy: (lyra)
Does anyone know why it is that in Java 8 List.replaceAll doesn't return the list in question (post replacement (or even better, with lazy evaluation waiting to happen))?

That asked, going back before java 8, does anyone know why List.add doesn't return the list? I think the official reason is so that it can always return true so as to implement Collection.list. But that's kind of terrible...

I mean is there a bad reason, or just no reason at all? The entire point of java 8 lambdas is to reduce the amount you have to type...

I'd like this:
   System.out.println(new LinkedList().add(1).add(2).replaceAll(i -> i*i).add(3));

to generate this:
   [1,4,3]

Instead I have to do this:
   List list = new LinkedList<>();
   list.add(1);
   list.add(2);
   list.replaceAll(i -> i*i);
   list.add(3);
   System.out.println(list);

Is there some java 8 thing I haven't seen yet that might improve this?

Profile

danceboy: (Default)
danceboy

October 2017

S M T W T F S
1234567
8910111213 14
15161718192021
22 232425262728
293031    

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 24th, 2026 11:56 pm
Powered by Dreamwidth Studios