Java 10-functies: dit is nieuw
Met Java 10 komen er heel wat nieuwe functies naar je toe. We tonen u de acht belangrijkste wijzigingen in deze praktische tip.
JEP 286 - Inferentie van het lokale variabele type
Met JEP 286 kunnen ontwikkelaars onnodige manifeste verklaringen van lokale variabelen omzeilen. Hier kan het trefwoord "var" worden gebruikt om lokale variabelen te definiëren waarvan het gegevenstype rechtstreeks uit de toewijzing voortvloeit.
- Bijvoorbeeld, de opdracht "var list = new ArrayList ();" definieert een ArrayList van het type "String", die voorheen alleen mogelijk was met de opdracht "ArrayList list = new ArrayList ();".
JEP 296: Consolideer het JDK-bos in een enkele repository
Tot nu toe bestond JDK 9 uit acht verschillende repositories.
- Met JDK 10 moeten al deze (root, hotspot, corba, jaxws, jdk, jaxp, langtools en neushoorn) worden gecombineerd in één repository, waarbij JavaFX er niet één van is.
JEP 304: interface voor vuilnisman
De Garbace Collection is een automatische afvalinzameling.
- Met Java 10 komt een schone interface voor de vuilnismannen, die het mogelijk maakt om vuilnismannen uit te sluiten van een Java-build.
JEP 307: Parallel Full GC voor G1
De G1-vuilnisman is ontwikkeld om volledige collecties te voorkomen.
- Als de gelijktijdige collecties het geheugen niet snel genoeg kunnen herstellen, wordt een volledig GC-proces uitgevoerd.
- Dit moet worden bereikt door de afvalverzamelaar parallel te laten lopen.
JEP 310: Application Class Data Sharing
Deze JEP breidt de CDS-functie (Class Data Sharing) verder uit.
- Hier de starttijd en de hoeveelheid geheugen die nodig is om een programma tijdens de uitvoering te verbeteren.
- Hiermee kunt u toepassingsklassen in gedeelde archieven gebruiken.
JEP 312: Thread-Local Handshakes
Met dit voorstel kunt u ook een callback-functie op threads toepassen.
- Hiermee kunt u afzonderlijke threads stoppen, niet alleen in één keer.
JEP 313: Verwijder de Native-Header Generation Tool (javah)
Met de update naar Java 10 verdwijnt ook de "javah" -tool.
- Als alternatief kunt u de "javac" -functie gebruiken om native header-bestanden te schrijven.
JEP 314: Extra Unicode Language-Tag-extensies
De nieuwe Unicode-extensies worden ook toegevoegd aan Java 10 java.util.Locale en alle bijbehorende API's.
Leer Java programmeren!
Ben je nog niet bekend met Java en wil je de programmeertaal leren? Lees dan onze Java-tutorials, waarin we de eerste stappen toelichten.
In de volgende praktische tip leert u hoe u voorwaarden en lussen in Java kunt gebruiken.