Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ The lambda expression Java8 (constructor references)     - Install Rubinius testing Ubuntu 14.04 native threads (Linux)

- Ubuntu prompt / lack of boot space solutions (Linux)

- CentOS installation of the ftp (Linux)

- About Linux operating system security (Linux)

- Macro Analysis Performance: PHP Performance Analysis and Experiment (Programming)

- Linux / Unix system-level IO (Linux)

- CentOS 6.x systems installation + NIC driver installation (Realtek PCIe GBE Family Controller for Linux) (Linux)

- Linux system firewall defense network attacks (Linux)

- It is time to upgrade your gulp 4.0 (Programming)

- CentOS 6.5 boot automatically mount the hard drive (Linux)

- PHP call a Python program (Programming)

- Five useful commands to manage file types and system time in linux (Linux)

- Installation of Python2.7.10 under CentOS 6.4 (Linux)

- Extended use of the swap file swap space on Linux (Linux)

- Ubuntu 14.10 PPA installed Android Studio (Linux)

- Linux directory configuration (Linux)

- CentOS use wget (Linux)

- GO five stages of language learning (Programming)

- How to protect the Apache website under Linux system (Linux)

- Make command Detailed Tutorial (Programming)

 
         
  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:      
 
- Batch kill processes using awk command (Linux)
- The Java way to stop a thread of execution (Programming)
- How to install OpenOffice Ubuntu or Linux Mint (Linux)
- Linux Tutorial ---- fundamentals of data traffic redirection (Linux)
- 7 JavaScript interview questions (Programming)
- Oracle table space create large files (Database)
- BCP importing and exporting large amounts of data Practice (Database)
- Linux linux system security (Linux)
- PL / SQL how to make the program every few seconds to insert a data (Database)
- Vi editor Introduction (Linux)
- Three kinds of implementation model of the Linux thread history (Programming)
- Json data with double backslashes to a single backslash Json data processing (Programming)
- Windows Ubuntu dual system a key Ghost, grub rescue prompt solution (Linux)
- To install Internet security firewall Raiders (Linux)
- Learn about EditText little depth (Programming)
- To explore the caching mechanism for Android ListView (Programming)
- How linux network security configuration (Linux)
- SSL VPN SSL VPN access to security websites patron (Linux)
- C ++ 11 feature: decltype keywords (Programming)
- Linux commands to access the cheat sheet (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.