The content below is from the Android developer site:

enter image description here

According to the phrase it is expecting the developer to store this info in his head. Shouldn't this be simple if they kept only setDataAndType and let user to set both, either or none, in which we don't have to remember this caveat since it is taken care by design.

As the code is from Google, I would like to check with the community if there is any good reason for they doing this that I am missing to see?




setDataAndType(Uri, String)
  • 1
    this looks like a variation of “Comments are a code smell” where comments are moved from code to docs to aid API clients in using it. Note how docs of setType and setData offer similar warnings about one clearing other. When there seems to be too much explanation of how code is supposed to work (be it in comments or in API docs), the usual suspect is that something isn't quite right in design – gnat Sep 19 '14 at 16:10

From the fragment you show there is no good reason - if both URI type and MIME type can be present simultaneously, it seems strange to null either when setting the other. There might be hidden reasons, but I can't think of any right now, therefore I'm leaning towards "This just isn't a very good API".

(Note also that the API talks about "type" and "data", but the documentation talks about "URI" and "MIME type". Such inconsistent language is another sign of an inexperienced API writer.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.