java - How to work with non generic lists -
i have work older interface specifying methods bare list parameter.
void updateparameter(list param1, list param2);
obviously need implement them same signature.
@override public void updateparameter(list param1, list param2) { updateparam1( param1 ); updateparam2( param2 ); }
but new code? should keep working these old lists. should new method's signature take generic lists?
private void updateparam1( list<string> param1 ) { ... }
should explicitly convert/cast them?
what best practices here?
i stick philosophy of "don't let defects passed down stream". somewhere, unsafe type cast must happen (even if done under hood compiler). why not possible? way code downstream can clean , have problem in 1 place instead of scattered throughout code base. follows principle of "fail fast".
@override public void updateparameter(list param1, list param2) { list<string> param1typesafe = (list<string>)param1; list<string> param2typesafe = (list<string>)param2; updateparam1( param1typesafe ); updateparam2( param2typesafe ); //now else in codebase needs deal it. }
Comments
Post a Comment