Upgrade to Pro — share decks privately, control downloads, hide ads and more …

As Velhas Novas do Java 7

As Velhas Novas do Java 7

Carlos Alexandro Becker

June 05, 2014
Tweet

More Decks by Carlos Alexandro Becker

Other Decks in Programming

Transcript

  1. Agenda • Diamond Operator • Strings em Switch’s • Automatic

    Resource Management • Numeric Literals com Underscores • Exception Handling (multi-catch) • NIO 2.0 • Fork and Join • invokedynamic
  2. Diamond Operator // java 6 Map<String, List<String>> list6 = 


    new TreeMap<String, List<String>>(); // java 7 Map<String, List<String>> list7 = new TreeMap<>();
  3. String em Switch’s // java 6 AnEnum a = AnEnum.A;

    switch (a) { case A: doSomethingWhenA(); break; // … }
  4. String em Switch’s // java 7 String b = "b";

    switch(b) { case "b": doSomethingWhenB(); break; // … }
  5. Automatic Resource Management // java 6 BlahResource resource; try {

    resource = new BlahResource(); resource.doSomething(); } catch (Exception e) { log.error( “Maoeee”, e ); } finally { try { resource.close(); } catch (BlahResourceException e) { log.error( “Ah haee”, e ); } }
  6. Automatic Resource Management // java 7 try (BlahResource resource =

    new BlahResource()) { resource.doSomething(); } catch (Exception e) { log.error( “Maoeee”, e ); }
  7. Exception Handling // java 6 try { oneThousandCheckedExceptionsLater(); } catch

    (ExceptionOne e) { log.error(“Erro: ", e); } catch (ExceptionTwo e) { log.error(“Erro: ", e); } catch (ExceptionThree e) { log.error(“Erro: ", e); }
  8. Exception Handling // java 7 try { oneThousandCheckedExceptionsLater(); } catch

    (ExceptionOne | ExceptionTwo | ExceptionThree e) { log.error(“Erro:”, e); }