java-8

How to use CompletableFuture without risking a StackOverflowError?

倾然丶 夕夏残阳落幕 提交于 2020-01-04 06:28:45
问题 I want to walk the search space of an asynchronous function. I coded the logic as follows: /** * Assuming that a function maps a range of inputs to the same output value, minimizes the input value while * maintaining the output value. * * @param previousInput the last input known to return {@code target} * @param currentInput the new input value to evaluate * @param function maps an input to an output value * @param target the expected output value * @return the minimum input value that

How to use CompletableFuture without risking a StackOverflowError?

佐手、 提交于 2020-01-04 06:28:29
问题 I want to walk the search space of an asynchronous function. I coded the logic as follows: /** * Assuming that a function maps a range of inputs to the same output value, minimizes the input value while * maintaining the output value. * * @param previousInput the last input known to return {@code target} * @param currentInput the new input value to evaluate * @param function maps an input to an output value * @param target the expected output value * @return the minimum input value that

A peculiar feature of exception type inference in Java 8

北城以北 提交于 2020-01-04 04:53:08
问题 While writing code for another answer on this site I came across this peculiarity: static void testSneaky() { final Exception e = new Exception(); sneakyThrow(e); //no problems here nonSneakyThrow(e); //ERRROR: Unhandled exception: java.lang.Exception } @SuppressWarnings("unchecked") static <T extends Throwable> void sneakyThrow(Throwable t) throws T { throw (T) t; } static <T extends Throwable> void nonSneakyThrow(T t) throws T { throw t; } First, I am quite confused why the sneakyThrow call

Which class does LongAdder extends?

笑着哭i 提交于 2020-01-04 04:29:04
问题 While referring JavaDocs for LongAdder, it's extending Number class. Then while looking at source code , It's extending from Striped64 It's quite confusing for me, Why we can't specify in javadocs that LongAdder extending from Striped64 class ? Is it because Striped64 extends Number ? 回答1: Which class does LongAdder extends? As shown in the source, it extends Striped64 . Since that class is not public API, however, the Javadoc doesn't tell you that. Javadoc, by default, only generates

PSQLException - spring boot 1.4.1 - spring data jpa - offsetdatetime/localdatetime identified as Bytestream

。_饼干妹妹 提交于 2020-01-04 02:30:06
问题 While integrating spring data JPA with postgres. I have a DB table representing the following java object. private class A { @Column(name="createdTime", columnDefiniton="TIMESTAMP WITH TIMEZONE") OffsetDateTime dateTime; } I'm trying to save to this table, however, i am getting Caused by: org.postgresql.util.PSQLException: ERROR: column "created_time" is of type timestamp with time zone but expression is of type bytea Hint: You will need to rewrite or cast the expression. Position: 131 at org

javax.net.ssl.SSLHandshakeException: No appropriate protocol

99封情书 提交于 2020-01-04 01:51:25
问题 i have install tomcat 8(ssl support) with java 1.8. When start tomcat catalina out write javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) at sun.security.ssl.Handshaker.activate(Handshaker.java:503) at sun.security.ssl.SSLEngineImpl.kickstartHandshake(SSLEngineImpl.java:729) at sun.security.ssl.SSLEngineImpl.beginHandshake(SSLEngineImpl.java:756) at org.apache.tomcat.util.net.SecureNioChannel.reset(SecureNioChannel.java:94)

guava's Streams::findLast implementation

孤街醉人 提交于 2020-01-03 19:58:51
问题 I am looking into the implementation of Streams::findLast from guava and while trying to understand it, there were a couple of things that simply I could not grasp. Here is it's implementation: public static <T> java.util.Optional<T> findLast(Stream<T> stream) { class OptionalState { boolean set = false; T value = null; void set(@Nullable T value) { set = true; this.value = value; } T get() { checkState(set); return value; } } OptionalState state = new OptionalState(); Deque<Spliterator<T>>

Parse date-only as LocalDateTime in Java 8

眉间皱痕 提交于 2020-01-03 17:35:53
问题 I need to parse a field which is sometimes given as a date and sometimes as a date/time. Is it possible to use single datatype for this using Java 8 time API? Currently, I attempted to use a LocalDateTime for it, but for following invocation LocalDateTime.parse("1986-04-08", DateTimeFormatter.ofPattern("yyyy-MM-dd")) I get a java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 1986-04-08 of type java.time.format.Parsed This is part of some

Parse date-only as LocalDateTime in Java 8

懵懂的女人 提交于 2020-01-03 17:32:14
问题 I need to parse a field which is sometimes given as a date and sometimes as a date/time. Is it possible to use single datatype for this using Java 8 time API? Currently, I attempted to use a LocalDateTime for it, but for following invocation LocalDateTime.parse("1986-04-08", DateTimeFormatter.ofPattern("yyyy-MM-dd")) I get a java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 1986-04-08 of type java.time.format.Parsed This is part of some

Arrays.parallelSort vs Collections.sort

雨燕双飞 提交于 2020-01-03 15:07:05
问题 I was checking a post that wanted to know how to use Comparator and a Orange fruit to be first all the time. From the post toString method was missing so I added to my code @Override public String toString(){ return fruitName +" " + fruitDesc; } The given answer to the post was use Collection.sort Collections.sort(fruits, new Comparator<Fruit>() { @Override public int compare(Fruit o1, Fruit o2) { if (o1.getFruitName() != null && o1.getFruitName().equalsIgnoreCase("orange")){ return -1; } if