private static void requireIdOfMatchingType(ReferenceDataType referenceType, DocumentId id) {
        String expectedTypeName = referenceType.getTargetType().getName();
        if (!id.getDocType().equals(expectedTypeName)) {
            throw new IllegalArgumentException(String.format(
                    "Can't assign document ID '%s' (of type '%s') to reference of document type '%s'",
                    id, id.getDocType(), expectedTypeName));
        }
    }
Creates a reference pointing to a particular document instance in the document
type referenced by <code>referenceType</code>.

@param referenceType reference target type
@param documentId document ID of the same document type as that given by <code>referenceType</code>
@throws IllegalArgumentException if documentId is not of the expected document type
document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java