Preskočiť na hlavný obsah

Príspevky

Zobrazujú sa príspevky z dátumu február, 2015

Java 8 / did U know?

JavaScript engine Engine Nashorn replaces old one (Rhino) as the new default JavaScript engine for the Oracle jvm. Nashorn is faster. It uses the invokedynamic feature of the jvm. "jjs" is Nashorn command line tool. Optional 8 comes with the Optional class (java.util.Optional) for avoiding nulls (NullPointerException). It is very similar to Google’s Optional, which is similar to Nat Pryce’s Maybe or Scala’s Option class. Streams What is a Stream? Stream is a interface (java.util.stream.Stream) and represents a sequence of some objects. However, unlike the Iterator, it supports parallel execution. The Stream supports the map/filter/reduce design pattern and executes lazily, forming the basis (along with lambdas) for functional-style programming in Java 8. Example: // finding a maximum max = list.stream().reduce(0.0, Math::max);

Get Enum constant of an Enum by String

Method cast(Class, String) builds the enum value constant of the specified Enum. The name must match exactly (case) an identifier used to declare an enum constant in the given Enum. @SuppressWarnings({ "rawtypes", "unchecked" }) public static <E extends Enum<E>> E cast(String name, Class&lt;E> clazz) { if (clazz == null || name == null || name.isEmpty()) { return null; } try { return (E) Enum.valueOf((Class<Enum>) clazz, name); } catch (Throwable e) { throw new RuntimeException("Enum cast error: '" + name + "' in not valid value of '" + clazz.getName() + "'"); } }