java8 / java8inaction Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I downloaded the lambdasinaction code example, but there are some errors.
For example:
The method flatMapping(( dish) -> {}, toSet()) is undefined for the type Grouping in chap3 package, The code: private static Map<Dish.Type, Set<String>> groupDishTagsByType() { return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet()))); }
And The method filtering(( dish) -> {}, toList()) is undefined for the type Grouping in chap3 package, The code private static Map<Dish.Type, List<Dish>> groupCaloricDishesByType() { return menu.stream().collect(groupingBy(Dish::getType, filtering(dish -> dish.getCalories() > 500, toList()))); }
When I practice, encountered a lot of errors . The method toList() 、groupingBy、comparing()....is undefined for the type TestStream.
By the way, i used jdk 1.8.0.171,Is it because the JDK version is too low ?
and update the README.
Not able to compile the code as its throwing lots of ERROR.
I have installed jdk9
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
my idea environment jdk is 9
I think that replace "lambdasinaction/chap3/data.txt"
with ExecuteAround.class.getResource("/lambdasinaction/chap3/data.txt").getPath()
should solve the problem.
Change the 'Make sure to have JDK8 installed' to 'Make sure to have JDK9 installed' to avoid the build failure.
This field can be define as a private
private static final long THRESHOLD = 10_000;
class: lambdasinaction.chap10.OperationsWithOptional
line 15 and line 18
The method or(() -> {}) is undefined for the type Optional
class: lambdasinaction.chap10.OptionalMain
line 21
The method flatMap(Function<? super Optional,? extends Stream<? extends R>>) in the type Stream<Optional> is not applicable for the arguments (Optional::stream)
class: lambdasinaction.chap6.Grouping
line 36
The method flatMapping(( dish) -> {}, toSet()) is undefined for the type Grouping
line 41
The method filtering(( dish) -> {}, toList()) is undefined for the type Grouping
class: lambdasinaction.chap6.PartitionPrimeNumbers
line 36
The method takeWhile(( i) -> {}) is undefined for the type Stream
I would love to use it for testing Java 8 support for JavaParser (https://github.com/matozoid/javaparser)
String[] stringArray = {"A,B","B,A","C,D","C,B","A,V"};
stringArray.stream() ------>> Cannot invoke stream() on the array type String[]
is it not good to have streaming on Array as well? :)
public static boolean isPrime(List<Integer> primes, Integer candidate) {
double candidateRoot = Math.sqrt((double) candidate);
//return takeWhile(primes, i -> i <= candidateRoot).stream().noneMatch(i -> candidate % i == 0);
return primes.stream().**takeWhile**(i -> i <= candidateRoot).noneMatch(i -> candidate % i == 0);
}
-> the function takeWhile is invalid or doesn't exists
I used openjdk 10 to run it. Openjdk 8 can't compile and run
BestPriceFinder.java
public Stream<CompletableFuture> findPricesStream(String product) {
return shops.stream()
.map(shop -> CompletableFuture.supplyAsync(() -> shop.getPrice(product), executor))
.map(future -> future.thenApply(Quote::parse))
.map(future -> future.thenCompose(quote -> CompletableFuture.supplyAsync(() -> Discount.applyDiscount(quote), executor)));
}
private static Map<Dish.Type, Set> groupDishTagsByType() {
return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet())));
}
-> flatMapping shown as invalid and don't compile the class
private static Map<Dish.Type, List<Dish>> groupCaloricDishesByType() {
// return menu.stream().filter(dish -> dish.getCalories() > 500).collect(groupingBy(Dish::getType));
return menu.stream().collect(groupingBy(Dish::getType, filtering(dish -> dish.getCalories() > 500, toList())));
}
-> filtering shown as invalid and don't compile the class
I have the first edition of the book. I just cloned the repo and tried to build with jdk8 and it's broken all over the place. Could you create a tag or branch for the Java 8 version?
I try to compile sources on Mac with Java 1.8.0_91
I get:
chojnasm-ml:Java8InAction chojnasm$ mvn compile
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for manning:lambdasinaction:jar:1.0
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-shade-plugin is missing. @ line 44, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building lambdasinaction 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ lambdasinaction ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ lambdasinaction ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 100 source files to /Users/chojnasm/Downloads/Java8InAction/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.558 s
[INFO] Finished at: 2017-02-27T14:27:45+00:00
[INFO] Final Memory: 9M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project lambdasinaction: Fatal error compiling: invalid target release: 1.9 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
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.