17. Avant
List<String> list = new ArrayList<String>();
Map<String, Integer> map = new HashMap<String, Integer>();
Map<String, List<BigDecimal>> map2 = new HashMap<String, Lis
18. Après
List<String> list = new ArrayList<>();
Map<String, Integer> map = new HashMap<>();
Map<String, List<BigDecimal>> map2 = new HashMap<>();
19. ZE nouveauté !
Un réel intérêt : éviter des bugs bêtes
try (BufferedReader reader = new BufferedReader(…)) {
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
} catch (IOException e) {
System.err.println("Erreur : " + e.getMessage());
}
finally{…} close()
20. java.lang.AutoCloseable
public class MyResource implements AutoCloseable {
...
@Override
public void close() throws Exception {
// Your stuff here !
}
}
21. @SafeVarargs
@SafeVarargs
public static <T> void addToList(List<T> listArg,
T... elements) {
for (T x : elements) {
listArg.add(x);
}
}
Type safety: Potential heap pollution via varargs parameter elements
22. java.util.Objects
9 méthodes utilitaires sur les « Object »
Un vrai + pour du code plus simple, plus
lisible
Deux exemple dans la démo :
› Objects.toString()
› Objects.hash()
24. Exemple de la copie de fichiers
› java.nio.file.*
FileSystem fs = FileSystems.getDefault();
Path src = fs.getPath("/home", "source.txt");
Path tgt = fs.getPath("/backup", "target.txt");
Files.copy(src, tgt, StandardCopyOption.REPLACE_EXISTING);
25. Un peu de lecture si vous le souhaitez …
http://groups.google.com/group/lescastcodeurs/msg/90ddf025c52a9412
26. Tirer parti des processeurs multiples
API de programmation parallèle
Voir aussi
› Map / Reduce
› Hadoop
› GridGain
27. Approche très simple
if (my portion of the work is small enough)
do the work directly
else
split my work into two pieces
invoke the two pieces and wait for the results
Démo !
http://download.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html
29. JSR 335 – Lamba Expressions
› Closures
› Fonctions anonymes
x -> x + 1
(x) -> x + 1
(int x) -> x + 1
(int x, int y) -> x + y
(x, y) -> x + y
http://mail.openjdk.java.net/pipermail/lambda-dev/2011-September/003936.html
30. Modularité : Projet JIGSAW
module-info.java
module com.greetings @ 0.1 {
requires jdk.base; // default to the highest available
version requires org.astro @ 1.2;
class com.greetings.Hello;
}
http://openjdk.java.net/projects/jigsaw/