Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ The lambda expression Java8 (constructor references)     - Installation and deployment of Hadoop 2.7.1 on Ubuntu 14.04 LTS (Server)

- Spring Data MongoDB combat (Database)

- socket busy poll of Linux kernel 3.11 to avoid sleep switch (Linux)

- 10 practical Java programming technology (Programming)

- Under CentOS 7 installation and deployment environment Ceph (Server)

- Spring next ActiveMQ combat (Programming)

- Use lsof restore accidentally deleted log files or database (Linux)

- How to use OpenVPN and PrivacyIDEA build two-factor authentication for remote access (Server)

- LVM Disk Manager Application (Linux)

- How to Install 3.16.7 CKT2 kernel in Ubuntu 14.10, Ubuntu 14.04 and its derivative versions (Linux)

- Linux Defensive / mitigate DDOS attacks (Linux)

- Use Docker / LXC quickly launch a desktop system (Linux)

- Linux centos rm directory does not prompt (Linux)

- Use value type build better applications Swift (Programming)

- Use SecureCRT to transfer files between local and remote hosts (Linux)

- Make Windows boot disk to install USB in Ubuntu Linux (Linux)

- jQuery update the content and method of use 3.0 (Programming)

- Linux environment Duplex (multi-machine) automatic mutual backup scheme (Linux)

- How to use jgit to manage Git submodule (Linux)

- Oracle 11g RMAN virtual private directory (Database)

 
         
  The lambda expression Java8 (constructor references)
     
  Add Date : 2018-11-21      
         
       
         
  The constructor method references cited with similar, except that the reference in the constructor method name is new. For example, Button :: new constructor Button class represents a reference. For classes with multiple constructors, selection of which depends on the context constructor. Suppose you have a list of strings, and you want the Button class constructor calls list is used to construct a string button list, you can use the following expression:
 
List < String> labels = ....;
Stream < Button> stream = labels.stream () map (Button :: new).;
List < Button> buttons = stream.collect (Collectors.toList ());

We'll discuss stream, map and collect method in more detail later. But now, it is important for each list element, map method calls Button (String) constructor. While the Button class has multiple constructors, but the compiler can infer from context and pick with only a String argument constructor.

You can use the array type constructor to write references. For example, int [] :: new constructor is a parameter containing a reference, this parameter is the length of the array. It is equivalent to a lambda expression x -> new int [x]. Array constructor references can be used to bypass restrictions java one. In Java, you can not construct an array of generic type T. Expression new T [n] is wrong, because it will be erased to new Object [n].

The API for developers to write is a problem. For example, suppose we want to construct a set of buttons, Stream interface has a return Object array toArray () method:

Object [] buttons = stream.toArray ();

But that does not make us satisfied. Users want a button object, rather than a set of Object objects. Stream API reference by the constructor to solve this problem. It allows the Button [] :: new method is passed to the toArray:

Button [] buttons = stream.toArray (Button [] :: new);

toArray call the constructor method to obtain an array of the correct type. It will then fill out and return the array.
     
         
       
         
  More:      
 
- PHP security Programming Advice (Programming)
- Use Swift remove the spaces in the string (Programming)
- Python-- for anomalies and reflection of objects articles (Programming)
- Node.js developers must know four JavaScript concepts (Programming)
- PostgreSQL use pgpool achieve high availability (Database)
- CentOS 6.x Basic System Optimization after installation (Linux)
- OpenSUSE GPG Comments (Linux)
- Java collections series (Programming)
- Using Linux command line and execute PHP code (Programming)
- Android imageView in the Src and Background (Programming)
- Easy to install CentOS 6.6 desktop environment (Linux)
- The security administrator network analysis tools SATAN Introduction under Linux (Linux)
- DataGuard a hardware issue warnings found (Database)
- General Linux interface server parameter tuning (Server)
- Object-oriented language Java some of the basic features (Programming)
- Oracle 12C RAC on temporary table space Enlighten (Database)
- Ubuntu 14.04 installation and configuration environment variable JDK1.8.0_25 (Linux)
- Achieve single backup of MySQL by innobackupex (Database)
- C language binary tree counts words (Programming)
- C + + secondary pointer memory model (pointer array) (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.