blob: 3a4cc01c161931bd2746060ac048e027d4abf8fe [file] [log] [blame]
Clément Béra29105372022-09-22 13:10:50 +02001// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package collectiontoarray;
6
7import java.util.ArrayList;
8import java.util.Arrays;
9import java.util.List;
Clément Béraaecefb02023-01-19 14:51:06 +010010import java.util.function.IntFunction;
Clément Béra29105372022-09-22 13:10:50 +020011
12public class Main {
13 public static void main(String[] args) {
14 List<String> list = new ArrayList<>();
15 list.add("one");
16 list.add("two");
17 // This default method was added in Android T.
18 String[] toArray = list.toArray(String[]::new);
19 System.out.println(Arrays.toString(toArray));
Clément Béraaecefb02023-01-19 14:51:06 +010020
21 List<String> myList = new MyList<>();
22 myList.add("one");
23 myList.add("two");
24 // This default method was added in Android T.
25 String[] toArray2 = myList.toArray(String[]::new);
26 System.out.println(Arrays.toString(toArray2));
27 }
28
29 @SuppressWarnings("all")
30 public static class MyList<T> extends ArrayList<T> {
31 public <T> T[] toArray(IntFunction<T[]> generator) {
32 System.out.println("Override");
33 return super.toArray(generator);
34 }
Clément Béra29105372022-09-22 13:10:50 +020035 }
36}