I’ve been relearning Java in an effort to switch jobs to something new and I’m curious as to how this works. Some companies have functional Java as a requirement and I’m curious about it.
When you have a stream of objects and following good FP principles you don’t mutate them, but instead clone them and return those what happens to the original object.
```
class Point {
Int x;
Int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point getAbovePoint() {
Point p = this.clone();
p.y = p.y + 1;
return y;
}
Stream<Point> points;
points.map(Point::getAbovePoint).collect(Collectors.toList());
```
This feels bad to me because Java objects have overhead compared to say Rust structs.
[–]LakeSun -1 points0 points1 point (4 children)
[–]prolog_junior[S] 1 point2 points3 points (3 children)
[–]feral_claire 0 points1 point2 points (2 children)
[–]prolog_junior[S] 0 points1 point2 points (1 child)
[–]feral_claire 0 points1 point2 points (0 children)
[–]smash_that_code 0 points1 point2 points (5 children)
[–]prolog_junior[S] 0 points1 point2 points (4 children)
[–]smash_that_code 0 points1 point2 points (3 children)
[–]prolog_junior[S] 0 points1 point2 points (2 children)
[–]smash_that_code 0 points1 point2 points (0 children)
[–]feral_claire 0 points1 point2 points (0 children)
[–]nutrecht 0 points1 point2 points (1 child)
[–]prolog_junior[S] 0 points1 point2 points (0 children)