Answer the question
In order to leave comments, you need to log in
New features of java 8, to use or not?
I know that java 8 is not so new anymore, but until this time I tried to figure it out with 7 and decided not to go any further. Today I looked at the list of new features in java 8 and ... somehow I doubted. Is it worth using them? In terms of how important it is to be able to use them. Because, for example, lambdas, although they shorten the code, are in some way "magic" that hides from us part of what is really happening.
Answer the question
In order to leave comments, you need to log in
You can start small if you are afraid of streams. Let's say this code snippet in Java7:
Map<String, List<Item>> items = new HashMap<>();
public void addItem(String key, Item item) {
List<Item> list = items.get(key);
if(list == null) {
list = new ArrayList<>();
items.put(key, list);
}
list.add(item);
}
Map<String, List<Item>> items = new HashMap<>();
public void addItem(String key, Item item) {
items.computeIfAbsent(key, k -> new ArrayList<>()).add(item);
}
If the boss allows you to use Java 8, then go ahead with the song =)
I agree with Applez. Well, from myself ...
Firstly: about the "magic" - all programming is like that, if you do not know the principle of operation of microcontrollers and at what stage the electrical voltage develops into code.
Second, who are you to question the work of the Java language development team? =)
In order for, say, the Stream API not to be “magic” for you, watch the video from Sergey Kuksenko at https://www.youtube.com/user/JUGRuVideo
For simple cases, the code can be executed a little slower, for complex ones it can be faster. In any case, you will get more expressiveness and, as a result, safety (the same applies to Optional).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question