Java in the Past, Java in the Future

Preview:

Citation preview

From External IterationTo Internal Iteration

List<Long> nums = ...;List<Long> nums2 = new ArrayList<>();

for (long n: nums) { nums2.add(n*2L);}

BeforeList<Long> nums = ...;

List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());

List<Long> nums = ...;

List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());

Boilerplate!

List<Long> nums = ...;

List<Long> nums2 = nums.stream() .map(

n -> n*2L ) .collect(Collectors.toList());

After

From External IterationTo Internal Iteration

List<Long> nums = ...;

List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());

From External IterationTo Internal Iteration

List<Long> nums = ...;

List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());

Boilerplate!

From External IterationTo Internal Iteration

List<Long> nums = ...;

List<Long> nums2 = nums.stream() .map(

n -> n*2L ) .collect(Collectors.toList());

After

Recommended