java-8

ConcurrentHashmap in JDK8 code explanation

南笙酒味 提交于 2019-12-31 22:40:14
问题 I have been trying to understand the ConcurrentHashMap functions in JDK8, in contrast of how it was in JDK7 (which, in addition to the source code, can be found explained quite well by some nice folks out there such as Richard http://www.burnison.ca/articles/the-concurrency-of-concurrenthashmap). It looks like have been changed quite a bit in JDK8 - e.g. there is no more 'segment' per se, but somehow I got a feeling that the changes are meant to make the code simpler? I'm having some

Elasticsearch installation : Error missing 'server' JVM at …jvm.dll

橙三吉。 提交于 2019-12-31 22:09:12
问题 After having downloaded elasticsearch and unzipped it following the steps in this link: Install Elastic Search on Windows I am receiving the following error: Error: missing 'server' JVM at 'C:\Program Files (x86)\Java\jre1.8.0_131\bin\server\jvm.dll'. Please install or use the JRE or JDK that contains these missing components. Note: I also had to install the JDK8 as suggested in this resolution Should I change something in the .config file? Maybe this line? # force the server VM (remove on 32

Java 8: More efficient way of comparing lists of different types?

人走茶凉 提交于 2019-12-31 21:12:53
问题 In a unit test, I want to verify that two lists contain the same elements. The list to test is build of a list of Person objects, where one field of type String is extracted. The other list contains String literals. One often finds the following code snippet to accomplish this task (see this answer): List<Person> people = getPeopleFromDatabasePseudoMethod(); List<String> expectedValues = Arrays.asList("john", "joe", "bill"); assertTrue(people.stream().map(person -> person.getName()).collect

Java 8: More efficient way of comparing lists of different types?

筅森魡賤 提交于 2019-12-31 21:12:36
问题 In a unit test, I want to verify that two lists contain the same elements. The list to test is build of a list of Person objects, where one field of type String is extracted. The other list contains String literals. One often finds the following code snippet to accomplish this task (see this answer): List<Person> people = getPeopleFromDatabasePseudoMethod(); List<String> expectedValues = Arrays.asList("john", "joe", "bill"); assertTrue(people.stream().map(person -> person.getName()).collect

Why there is no BooleanConsumer in Java 8?

有些话、适合烂在心里 提交于 2019-12-31 17:38:24
问题 I'm afraid that this is somewhat a silly question. Is there anybody can tell me why there is no BooleanConsumer opposite to BooleanSupplier? Is there any reason other than "because simply there isn't"? Should I create my own one? Or am I missing something else? public interface BooleanConsumer { void accept(boolean value); default BooleanConsumer andThen(final BooleanConsumer after) { return v -> { accept(v); after.accept(v); } } } Update Where to use? I'm writing a library that uses much of

Format a date using the new date time API

自闭症网瘾萝莉.ら 提交于 2019-12-31 17:38:12
问题 I was playing with the new date time API but when running this: public class Test { public static void main(String[] args){ String dateFormatted = LocalDate.now() .format(DateTimeFormatter .ofPattern("yyyy-MM-dd HH:mm:ss")); System.out.println(dateFormatted); } } It throws: Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay at java.time.LocalDate.get0(LocalDate.java:680) at java.time.LocalDate.getLong(LocalDate.java:659) at java.time

Why there is no BooleanConsumer in Java 8?

我与影子孤独终老i 提交于 2019-12-31 17:37:50
问题 I'm afraid that this is somewhat a silly question. Is there anybody can tell me why there is no BooleanConsumer opposite to BooleanSupplier? Is there any reason other than "because simply there isn't"? Should I create my own one? Or am I missing something else? public interface BooleanConsumer { void accept(boolean value); default BooleanConsumer andThen(final BooleanConsumer after) { return v -> { accept(v); after.accept(v); } } } Update Where to use? I'm writing a library that uses much of

Why does \R behave differently in regular expressions between Java 8 and Java 9?

Deadly 提交于 2019-12-31 10:57:05
问题 The following code compiles in both Java 8 & 9, but behaves differently. class Simple { static String sample = "\nEn un lugar\r\nde la Mancha\nde cuyo nombre\r\nno quiero acordarme"; public static void main(String args[]){ String[] chunks = sample.split("\\R\\R"); for (String chunk: chunks) { System.out.println("Chunk : "+chunk); } } } When I run it with Java 8 it returns: Chunk : En un lugar de la Mancha de cuyo nombre no quiero acordarme But when I run it with Java 9 the output is different

Why does \R behave differently in regular expressions between Java 8 and Java 9?

末鹿安然 提交于 2019-12-31 10:57:03
问题 The following code compiles in both Java 8 & 9, but behaves differently. class Simple { static String sample = "\nEn un lugar\r\nde la Mancha\nde cuyo nombre\r\nno quiero acordarme"; public static void main(String args[]){ String[] chunks = sample.split("\\R\\R"); for (String chunk: chunks) { System.out.println("Chunk : "+chunk); } } } When I run it with Java 8 it returns: Chunk : En un lugar de la Mancha de cuyo nombre no quiero acordarme But when I run it with Java 9 the output is different

How to autocomplete lambdas in IntelliJ IDEA?

两盒软妹~` 提交于 2019-12-31 09:16:50
问题 I'm using IntelliJ IDEA 13 with Java 8 and wonder how to autocomplete lambdas. Before Java 8 I used anonymous inner classes of course. I auto completed by typing "new" and hitting Ctrl + Space : and choosing the first option. Now with Java 8 I want to generate lambdas as well, inferring parameters and all, but I can't find autocompletion for it. Note, this above example is quite easy, but when you have multiple parameters with generic types, e.g. JavaFX Listeners and the like, autocompletion