Home > Java > javaTutorial > How to implement java array reference

How to implement java array reference

WBOY
Release: 2023-04-17 20:58:01
forward
1782 people have browsed it

Explanation

1. The array can be regarded as a special class, and the writing method is consistent with the constructor reference. The formal parameter list of the abstract method of the functional interface is consistent with the formal parameter list of the constructor.

2. The format is

数组类型 [] :: new
Copy after login

Example

//数组引用
//Function中的R apply(T t)
@Test
public void test4() {
    Function<Integer, String[]> func1 = length -> new String[length];
    String[] arr1 = func1.apply(5);
    System.out.println(Arrays.toString(arr1));
 
    System.out.println("====================");
 
    //使用方法引用
    Function<Integer,String[]>func2=String[]::new;
    String[] arr2 = func2.apply(10);
    System.out.println(Arrays.toString(arr2));
}
Copy after login

The above is the detailed content of How to implement java array reference. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template