@SuppressWarnings ( "unchecked" ) private Object getPropVal( Object obj, String propName, Queue<BeanLevelInfo> beanInfos ) { BeanLevelInfo info = beanInfos.remove(); if ( beanInfos.isEmpty() ) { return getObjFromBeanInfo( obj, info ); } obj = getObjFromBeanInfo( obj, info ); switch ( info.dim ) { case LIST: return ( (List) requireNonNull( obj ) ).stream() .map( o -> getPropVal( o, propName, newLinkedList( beanInfos ) ) ) .collect( Collectors.toList() ); case ARRAY: return Arrays.stream( (Object[]) requireNonNull( obj ) ) .map( o -> getPropVal( o, propName, newLinkedList( beanInfos ) ) ) .toArray( Object[]::new ); case NONE: return getPropVal( obj, propName, beanInfos ); } throw new IllegalStateException( "Unexpected value of BeanLevelInfo.dim " + info.dim ); }