Java 8 refers to the newest version of the Java platform.

learn more… | top users | synonyms

-2
votes
0answers
37 views

What are the limitations of Factory design patterns? How to overcome?

As we know there are many ways, by which we can break a singleton implementation in Java. Similarly do we have any ways by which we can break factory method implementation in Java? if yes then how to ...
7
votes
3answers
184 views

Why does java.time have methods for creating objects instead of just constructors?

In the new java.time package the core classes are using the factory method of instead of a public constructor. Even though I like the cosmetics of the of method I can't see a good reason to not use a ...
-3
votes
0answers
18 views

connecting java application to mysql server 2014 [on hold]

Please I want the driver name for connecting java application to mysql server 2014. This is what I am doing. I get the error class not found import java.sql.Connection; import java.sql.DriverManager;...
0
votes
1answer
191 views

Java is not actually a pure object oriented programming language since it needs primitives Why?

here my Question it is said that "Java is not actually a pure object oriented programming language since it needs primitives" I want to know that how data types can affect to java be an pure object ...
5
votes
0answers
222 views

What lambda function optimizations, if any, are planned for Java 9 and beyond?

I'm working on a high-performance project where Java 8's lambda functions are enormously useful. I've found, however, that they're memory inefficient when used en masse. For example, suppose I need to ...
1
vote
1answer
72 views

Is this indexed approach to java rts game development valid and how can I improve it?

I have class GameState laid out to basically hold an Array of Players, an Array of StarSystems, and a few other fields that need to persist from save to save. Each GameObject keeps track of its own id,...
20
votes
3answers
1k views

Why is Optional.get() without calling isPresent() bad, but not iterator.next()?

When using the new Java8 streams api to find one specific element in a collection, I write code like this: String theFirstString = myCollection.stream() .findFirst() .get()...
0
votes
3answers
109 views

Cyclic dependency in this project design

I have 2 modules (containing multiple classes). Let's call them Module A and Module B. Module B has a dependency on Module A: Module B -> Module A. Now, I have created an utility class C, which A ...
1
vote
1answer
66 views

Java 8 Optional in JavaScript

I like the idea of Optional in Java which we can use to say that the object may or may not be available. I am now learning JavaScript and when trying to find an equivalent, came only across optional-...
2
votes
1answer
132 views

Supporting Multiple Java Versions in OSS Libraries

I am in the process of standing up my first OSS Java lib (GitHub/Maven) that an open source hardware community will be making fair/moderate use of. I am writing this library with Java 8 and managing ...
3
votes
1answer
317 views

Is it OK to do IO inside java 8 streams?

Example to question in title: List<UUID> ids = dao1.getContactsOfUser(userId); List<String> contact_names = ids.stream .map(uid -> dao2.getContactByUid(uid)) //is it ok? ....
5
votes
9answers
432 views

Why is using an optional preferential to null-checking the variable?

Take the two code examples: if(optional.isPresent()) { //do your thing } if(variable != null) { //do your thing } As far as I can tell the most obvious difference is that the Optional ...
6
votes
2answers
326 views

Is it an antipattern to use peek() to modify a stream element?

Suppose I have a stream of Things and I want to "enrich" them mid stream, I can use peek() to do this, eg: streamOfThings.peek(this::thingMutator).forEach(this::someConsumer); Assume that mutating ...
0
votes
1answer
67 views

How confusing is `new SomeCollection(values…)::contains` as a Predicate? [closed]

Traditionally, a function that want to skip certain items during processing will accept a Collection or var-args argument, but in the Java 8 world I think I should switch to Predicates. Now, since ...
6
votes
2answers
708 views

Should Java 8 Stream instances always be close()'d?

Quoth the Javadoc: Streams have a BaseStream.close() method and implement AutoCloseable, but nearly all stream instances do not actually need to be closed after use. Generally, only streams whose ...
0
votes
1answer
144 views

Do 'OR' conditional statement continue if already true? [duplicate]

I have a question in regards to Java conditional if statements. If I have a statement such as this: if(true || false){ //output } Will Java go inside of the the if statement as soon as it sees the ...
1
vote
3answers
109 views

usage of interface.super.print() in java8

In java8, we are using interface.super. Considering the below points There are 2 interfaces but none of the interfaces inherit to another. There is implementation class which is inheriting both of ...
0
votes
3answers
264 views

Multi inheritance in Java

Let's say I've got a generic java class Filter<InputType, OutputType> which receives an input object and transforms it to an output object. Now I've got two other classes (NoInputFilter<...
20
votes
3answers
3k views

Why should I use “functional operations” instead of a for loop?

for (Canvas canvas : list) { } NetBeans suggests me to use "functional operations": list.stream().forEach((canvas) -> { }); But why is this preferred? If anything, it is harder to read and ...
12
votes
1answer
776 views

Is it good practice to implement two Java 8 default methods in terms of each other?

I'm designing an interface with two related methods, similar to this: public interface ThingComputer { default Thing computeFirstThing() { return computeAllThings().get(0); } ...
6
votes
1answer
3k views

Is Collection.stream().filter().forEach() inefficient compared to a standard for each loop?

IntelliJ IDEA recommended to me just now to replace the following for-each loop with a Java 8 "forEach" call: for (Object o : objects) { if (o instanceof SomeObject) { ...
1
vote
1answer
348 views

What is the “->” symbol called?

I have seen the -> operator/symbol in Java 8 predicates recently and wondered what its name is. I know that it is used in lambda expressions, but I know that the symbol for lambda is λ, so that's ...
1
vote
0answers
54 views

Can't figure out how to parallelize the calculation of the amount of offspring expected for species in genetic algorithm

I developed a genetic algorithm in java 8 taking advantage of its reasonably free parallelism opportunities with Streams. As you are likely aware, running the epochs takes its time for even a test ...
28
votes
4answers
4k views

Is there a performance benefit to using the method reference syntax instead of lambda syntax in Java 8?

Do method references skip the overhead of the lambda wrapper? Might they in the future? According to the Java Tutorial on Method References: Sometimes... a lambda expression does nothing but ...
1
vote
2answers
84 views

Is it a good idea to contextually name predefined functional interfaces?

I am currently working with Java 8 and using functional interfaces a lot. I often find myself writing code like this: public interface MessageHandler extends Consumer<String> { } Is this a ...
26
votes
3answers
9k views

What is the name of a function that takes no argument and returns nothing? [closed]

In Java 8's java.util.function package, we have: Function: Takes one argument, produces one result. Consumer: Takes one argument, produces nothing. Supplier: Takes no argument, produces one result. ....
15
votes
3answers
549 views

Is it a sane thing to return Streams wherever we would normally return Collections?

While developing my API that is not tied to any legacy code, I often find myself writing methods that are purely Streams pipeline terminated by collecting the results. Like this one: ImmutableSet<...
0
votes
2answers
148 views

Java Streams API Documentation

Currently learning Java so this may be a question resulting from lack of understanding of Java (while also learning Streams API) In the declarations of function I often see two templated types for ...
5
votes
3answers
317 views

Does it make sense to split up an existing multi-method interface into several single method interfaces just to take advantage of lambdas?

Say I have an existing callback interface that has multiple methods. To illustrate my point I use a callback the likes that you would see in code that performs some HTTP client operations: public ...
1
vote
2answers
197 views

How the Stream.filter() method works?

I know how the lambda expresion works and I know it is an argument for .filter() that establish the criteria to filter with. But I don't get how .filter() uses the argument, in this case a lambda ...
4
votes
2answers
3k views

Is there any reason not to use Optional as a method argument in the case where you know the argument is something that may or may not be needed?

With Java 8, I've seen more and more articles about the use of Option/Optional. I understand what they trying to represent, and I see many examples of them being used as returns. However what I don't ...
37
votes
4answers
31k views

Why were default and static methods added to interfaces in Java 8 when we already had abstract classes?

In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override). In my (probably naive) view, there ...
13
votes
1answer
2k views

Passing a Scala function to a Java 8 method

The following Scala code works and can be passed to a Java method expecting a function. Is there a cleaner way to do this? Here's my first pass: val plusOne = new java.util.function.Function[Int,...
35
votes
6answers
11k views

Workaround for Java checked exceptions

I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of ...
45
votes
3answers
17k views

Why are the Java 8 java.time classes missing a getMillis() method?

Java 8 has a whole new library for dates and times in the package java.time which is very welcome thing to anyone who has had to use JodaTime before or hassle with making it's own date processing ...
6
votes
2answers
4k views

Are Interfaces with Java 8 Virtual Extension Methods the Same Thing as Mixins?

This post describes a new feature in Java 8 called virtual extension methods (formerly called default methods, or defender methods). In the example provided, an interface has one method, which is ...
3
votes
2answers
586 views

Why would someone use @Native annotations?

link : http://download.java.net/jdk8/docs/api/java/lang/annotation/Native.html In Java 8, there will be @Native annotations. Indicates that a field defining a constant value may be referenced ...
12
votes
1answer
2k views

Reasons for removal of function types in Java 8

I have been trying to understand why the JDK 8 Lambda Expert Group (EG) decided not to include a new function type into the Java programming language. Going over the mailing list I found a thread ...
26
votes
1answer
11k views

Type inference in Java 8

Is the introduction of the new lambda notation (see e.g. this article) in Java 8 going to require some kind of type inference? If so, how will the new type system impact the Java language as a whole?