richardwarburton / java-8-lambdas-exercises Goto Github PK
View Code? Open in Web Editor NEWExercises and Answers for Java 8 Lambdas book
License: MIT License
Exercises and Answers for Java 8 Lambdas book
License: MIT License
Hi !
I am reading your book.
I am a little confused about the writing here.
src/main/java/com/insightfullogic/java8/examples/chapter1/Album.java
public Album(String name, List<Track> tracks, List<Artist> musicians) {
Objects.requireNonNull(name);
Objects.requireNonNull(tracks);
Objects.requireNonNull(musicians);
this.name = name;
this.tracks = new ArrayList<>(tracks);
this.musicians = new ArrayList<>(musicians);
}
Is it correct to write like this:
public Album(String name, List<Track> tracks, List<Artist> musicians) {
Objects.requireNonNull(name);
Objects.requireNonNull(tracks);
Objects.requireNonNull(musicians);
this.name = name;
this.tracks = tracks;
this.musicians = musicians;
}
or
public Album(String name, List<Track> tracks, List<Artist> musicians) {
this.name = Objects.requireNonNull(name);
this.tracks = Objects.requireNonNull(tracks);
this.musicians = Objects.requireNonNull(musicians);
}
Hello,
could you please exaplain once again what's the difference between non-lambda code and it's lambda version? (Chapter 7: Testing, Debugging and Refactoring, site 98)
non-lambda code:
Logger logger = new Logger();
if (logger.isDebugEnabled()) {
logger.debug("Look at this: " + expensiveOperation());
}
lambda code:
Logger logger = new Logger();
logger.debug(() -> "Look at this: " + expensiveOperation());
What do we win by using the lambda version? We can hide the isDebugEnabled check in non-lambda code as well - don't we?
The Artist#isFrom(String nationality)
method always returns true
. The this
keyword has to be used when pointing the class member.
jdk8
f.fibonacci(15);
result:
{0=0, 1=1, 2=1, 3=2, 4=3, 5=5, 6=8, 7=13, 8=21, 9=34, 10=55, 11=89, 12=144, 13=233}
cache = new HashMap<>(); // Lack 14,15 why?
cache = new TreeMap<>(); // use TreeMap ok
Artist#copy
public Artist copy() {
List members = getMembers().map(Artist::copy).collect(toList());
return new Artist(name, members, nationality);
}
self invoke, and fall into an infinite loop
this issues occurs when i calculate array size,
this array about three minion arays,i hava 2G heap.this file is only 40m,and if i use no parallel,this
program only uses 50m, Ask,what's the cause
static void useStream(){
long uniqueWord = 0;
try (Stream<String> lines =
Files.lines(Paths.get("D:\\nlp\\dictionary\\CoreNatureDictionary.ngram.txt"), Charset.defaultCharset())){
long start = System.currentTimeMillis();
uniqueWord = lines.flatMap(line -> Arrays.stream(line.split(" "))).parallel().distinct().count();
// uniqueWord = lines.flatMap(line -> Arrays.stream(line.split(" "))).distinct().count();
System.out.println(uniqueWord);
long end = System.currentTimeMillis();
System.out.println( (end-start)+"ms");
}catch (IOException e){
e.printStackTrace();
}
}
the exercise file for Exercise 4.3 should not already contain solution.
Hi,
Recently I'm reading this book, and now encountered some problems. When I run com.insightfullogic.java8.answers.chapter6.OptimisationExampleFixed
, it hint
No matching benchmarks. Miss-spelled regexp?
Use EXTRA verbose mode to debug the pattern matching.
What's wrong? how to solve it?
import org.openjdk.jmh.Main;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.RunnerException;
The link entitled "Java 8 Lambdas" leads to a github 404 page.
This code in chapter 5 is not correct:
public long fibonacci(int x) { return cache.computeIfAbsent(x, n -> fibonacci(n-1) + fibonacci(n-2)); }
because you are not allowed to change the cache when you are using computeIfAbsent()
Exception in thread "main" java.util.ConcurrentModificationException
The sum of sqaures of numbers in [0, 1,000,000) should be 333332833333500000, but the excercise code below gives 584144992.
Should use LongStream and long instead.
ChatVerticle、User etc
This git repository contains support material for the Java 8 Lambdas book.
Tiny URL Link to the book is not working.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.