File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
guava/src/test/java/org/baeldung/guava/collections Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ package org .baeldung .guava .collections ;
2
+
3
+ import java .util .List ;
4
+
5
+ import org .junit .Test ;
6
+
7
+ import com .google .common .base .Function ;
8
+ import com .google .common .collect .Lists ;
9
+
10
+ public class GuavaCollectionsExamples {
11
+
12
+ @ SuppressWarnings ({ "unused" , "unchecked" })
13
+ @ Test
14
+ public final void whenCastingAllElementsOfACollectionToSubtype_thenCastIsOK () {
15
+ final class CastFunction <F , T extends F > implements Function <F , T > {
16
+ @ Override
17
+ @ SuppressWarnings ("unchecked" )
18
+ public final T apply (final F from ) {
19
+ return (T ) from ;
20
+ }
21
+ }
22
+
23
+ final List <Number > originalList = Lists .newArrayList ();
24
+ final List <Integer > selectedProductsQuick = (List <Integer >) (List <? extends Number >) originalList ;
25
+ final List <Integer > selectedProducts = Lists .transform (originalList , new CastFunction <Number , Integer >());
26
+ System .out .println (selectedProducts );
27
+ }
28
+
29
+ @ Test
30
+ public final void when_then () {
31
+
32
+ }
33
+
34
+ }
You can’t perform that action at this time.
0 commit comments