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

How to implement java array reference

WBOY
WBOYforward
2023-04-17 20:58:011718browse

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

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));
}

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete