@ SuppressWarnings ( "unchecked" ) public < R > R match ( Fn1 < A , R > fa , Fn1 < B , R > fb , Fn1 < C , R > fc ) { if ( sel == 0 ) { return fa . apply ( ( A ) item ) ; } else if ( sel == 1 ) { return fb . apply ( ( B ) item ) ; } else { return fc . apply ( ( C ) item ) ; } }
If sel is managed correctly it ensures that the cast is accurate .