Thanks for the replies. Yes, I'm resigned to the fact that it's definitely William. At least, that's what the enumerator wrote in 1871. This person appears in at least four Ancestry family trees. One of his sons is James Kennedy, but according to James's marriage certificate his father was called Matthew, and Matthew's death certificate confirms James as his son. Perhaps William and Matthew are the same person. I can't find any other records that are likely to be William. I suspect the family trees that link William to the James I'm interested in, are incorrect. I'll carry on looking.
Add: I can't find anything linking William to Margaret W a/e lsh.