java-8

How does @FunctionalInterface influence the JVM's runtime behavior?

自闭症网瘾萝莉.ら 提交于 2020-01-02 04:27:08
问题 My initial question was an exact duplicate of this one; that is, why is it that this interface has a runtime retention policy. But the accepted answer does not satisfy me at all, for two reasons: the fact that this interface is @Documented has (I believe) nothing to do with it (although why @Documented has a runtime retention policy is a mystery to me as well); even though many "would be" functional interfaces existed in Java prior to Java 8 ( Comparable as the answer mentions, but also

Spring 4 cannot execute Java 8 default methods

坚强是说给别人听的谎言 提交于 2020-01-02 02:45:07
问题 I have defined interface public interface MyInterface { default void setOrder(int a){ } default int getOrder(){return 123;} } and implementation public class MyInterfaceImpl implements MyInterface {} In my spring configuration file I have defined following bean: <bean id="a" class="my.package.MyInterfaceImpl"> <property name="order" value="999"/> </bean> When I create spring context I got following error: Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property

how to launch sonarqube?

情到浓时终转凉″ 提交于 2020-01-02 02:20:12
问题 for my studies I need to install sonarqube on an ubuntu server. I installed it following this tutorial : http://www.naturalborncoder.com/methodology/2015/05/27/sonarqube-on-ubuntu-14-04/ (I stopped before the proxying part) but I can't access to 127.0.0.1:9000. From the logs it look like there is a problem with elasticsearch when i launch sonarcube. /opt/sonar/log/sonar.log : --> Wrapper Started as Daemon Launching a JVM... Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org Copyright

Creating Map composed of 2 Lists using stream().collect in Java

故事扮演 提交于 2020-01-02 02:11:27
问题 As for example, there are two lists: List<Double> list1 = Arrays.asList(1.0, 2.0); List<String> list2 = Arrays.asList("one_point_zero", "two_point_zero"); Using Stream, I want to create a map composed of these lists, where list1 is for keys and list2 is for values. To do it, I need to create an auxiliary list: List<Integer> list0 = Arrays.asList(0, 1); Here is the map: Map<Double, String> map2 = list0.stream() .collect(Collectors.toMap(list1::get, list2::get)); list0 is used in order list1:

Replacing traditional newForLoop with Java 8 Streams

五迷三道 提交于 2020-01-02 02:03:07
问题 So, finally making a relatively large jump from Java 6 to Java 8, I've read up a fair amount of Java 8 Streams API. Unfortunately, almost all the examples that have been asked are almost close to what I'm trying to figure out how to do, but not close enough. What I have is final List<Function<? super Double, Double>> myList = generateList(); final double myVal = calculate(10); private double calculate(double val) { for (Function<? super Double, Double> function : this.myList) { val +=

Create custom Predicate with Set<String> and String as parameter

邮差的信 提交于 2020-01-02 01:36:48
问题 I have a String as "ishant" and a Set<String> as ["Ishant", "Gaurav", "sdnj"] . I need to write the Predicate for this. I have tried as below code, but it is not working Predicate<Set<String>,String> checkIfCurrencyPresent = (currencyList,currency) -> currencyList.contains(currency); How can I create a Predicate which will take Set<String> and String as a parameter and can give the result? 回答1: A Predicate<T> which you're currently using represents a predicate (boolean-valued function) of one

How to preserve newlines while reading a file using stream - java 8

做~自己de王妃 提交于 2020-01-02 01:20:11
问题 try (Stream<String> lines = Files.lines(targetFile)) { List<String> replacedContent = lines.map(line -> StringUtils.replaceEach(line,keys, values)) .parallel() .collect(Collectors.toList()); Files.write(targetFile, replacedContent); } I'm trying to replace multiple text patterns in each line of the file. But I'm observing that "\r\n"(byte equivalent 10 and 13) is being replaced with just "\r"(just 10) and my comparison tests are failing. I want to preserve the newlines as they are in the

Coverting String to LocalTime with/without nanoOfSeconds

时间秒杀一切 提交于 2020-01-02 01:06:06
问题 I need to convert a string to LocalTime (java-8 not joda) that may or maynot have nanoOfSeconds in the string. The String format is in the form of 07:06:05 or 07:06:05.123456 The string may or may not have a decimal place in the seconds and when it does there could be any number of characters to represent the Nano Seconds part. Using a DateTimeForamtter such as DateTimeFormatter dtf = DateTimeFormatter.ofPattern("H:mm:ss"); or DateTimeFormatter dtf = DateTimeFormatter.ofPattern("H:mm:ss

How to get a custom type instead of Integer when using Collectors.summingInt?

我与影子孤独终老i 提交于 2020-01-02 01:05:14
问题 I am currently creating a Map<String, Map<LocalDate, Integer>> like this, where the Integer represents seconds: Map<String, Map<LocalDate, Integer>> map = stream.collect(Collectors.groupingBy( x -> x.getProject(), Collectors.groupingBy( x -> x.getDate(), Collectors.summingInt(t -> t.getDuration().toSecondOfDay()) ) )); How could I instead create a Map<String, Map<LocalDate, Duration>> ? 回答1: To change that Integer from Collectors.summingInt to a Duration , you simply need to replace that

Why 'T.super.toString()' and 'super::toString' use a synthetic accessor method?

让人想犯罪 __ 提交于 2020-01-02 01:04:44
问题 Consider the following set of expressions: class T {{ /*1*/ super.toString(); // direct /*2*/ T.super.toString(); // synthetic Supplier<?> s; /*3*/ s = super::toString; // synthetic /*4*/ s = T.super::toString; // synthetic }} Which gives the following result: class T { T(); 0 aload_0 [this] 1 invokespecial java.lang.Object() [8] 4 aload_0 [this] 5 invokespecial java.lang.Object.toString() : java.lang.String [10] 8 pop // ^-- direct 9 aload_0 [this] 10 invokestatic T.access$0(T) : java.lang