@ Override public < T > T asObject ( String string , Class < T > valueType ) throws IllegalArgumentException { // at this point value type is guaranteed to be a Locale int dashIndex = string . indexOf ( ' ' ) ; if ( dashIndex == - 1 ) { throw new IllegalArgumentException ( String . format ( "Cannot convert |%s| to locale instance." , string ) ) ; } return ( T ) new Locale ( string . substring ( 0 , dashIndex ) , string . substring ( dashIndex + 1 ) ) ; }
Create locale instance from ISO - 639 language and ISO - 3166 country code for example en - US .