Java8 new features

Default extension method
Java8 adds an implementation of non-abstract methods to interface declarations and also becomes an extension method.

Public interface Formula {

Void doSomething();

Default void before() {

System.out.println ("I am an extension method");

}

}

Public class FormulaService implements Formula {

@Override

Public void doSomething() {

Before();

System.out.println ("I am the override method");

}

}

Lambda expression

Java8 introduces functional programming, and Lambda is the basis of functional programming.

List "String" list = Arrays.asList("a", "b", "c");

// before java8

CollecTIons.sort(list, new Comparator"String"(){

@Override

Public int compare(String o1, String o2) {

Return o1.compareTo(o2);

}

});

// lambda

CollecTIons.sort(list, (String o1, String o2) -》 {

Return o2.compareTo(o1);

});

// concise lambda

CollecTIons.sort(list, (String o1, String o2) -》 o2.compareTo(o1));

// More concise lambda

CollecTIons.sort(list, (o1, o2) -" o2.compareTo(o1));

Functional interface

A functional interface has one and only one abstract method declaration, where the attention is given to the @FunctionalInterface annotation. At this point, if a second abstract method is defined in the interface, the compiler will throw an exception. Of course, if you don't add this annotation, it won't work. If there are multiple abstract methods in the interface, and you use a lambda expression, an exception will be thrown at the call.

@FunctionalInterface

Public interface Formula "F,T"{

T convert(F var1);

}

Formula "String, Integer" function = (var1 -" Integer.valueOf(var1));

Integer var2 = function.convert("1000");

Method and constructor reference

The standard syntax for method references is class name: method name type example

JAVA8 new features

Reference static method

Formula "String, Integer" function = (Integer::valueOf);

Integer var2 = function.convert("1000");

An instance method that references any type of object

Public static void main(String[] args) {

String[] array = {"贱明", "学友"};

Arrays.sort(array, String::compareTo);

}

Reference constructor

// Define the factory

Interface PersonFactory "P extends Person" {

P create(String name);

}

// The constructor of the Person class

Public Person(String name) {

This.name = name;

}

// create

PersonFactory "Person" factory = Person::new;

Factory.create("贱明");

Capacitor for Electric Furnace

Capacitor for Electric Furnace, commonly referred to as capacitors, are capacitors, expressed in the letter C.Definition 1: a capacitor, as the name implies, is a "charging vessel", a device that holds charge.Capacitor.Capacitors are one of the most widely used electronic components in electronic equipment. They are widely used in the fields of interleaving, coupling, bypass, filtering, tuning circuit, energy conversion and control.Definition 2: a capacitor consisting of any two conductors (including wires) that are insulated from each other and are very close together.


Electronic Components Capacitors,High Voltage Capacitors,Low Frequency Capacitor,Water Pump Capacitor,Capacitor for Electric Furnace

YANGZHOU POSITIONING TECH CO., LTD , https://www.yzpstcc.com

Posted on