[SalesForce] Why can Map> be assigned to Map>

Assigning a sobject map to a specific sobject-type is not possible, i.e

Map<Id,SObject> sobjectById = new Map<Id,SObject>();
sobjectById.put(a.Id,a);

Map<Id,Account> accountById = (Map<Id,Account>) sobjectById;

This is expected and a solution is documented here

However, it is possible to assign a map of sobject lists to a map of sobject-specific types, for example

Map<Id,List<SObject>> sobjectListsById = new Map<Id,List<SObject>>();
sobjectListsById.put(a.Id,new List<SObject>{a});

Map<Id,List<Account>> accountListsById = sobjectListsById;

Why is the latter allowed?

EDIT

To add more details, I think this is related to lists. For example, I cannot assign an sObject variable to an Account variable

Account a = [SELECT Id FROM Account LIMIT 1];
Sobject s = a;
Account a2 = s;//this will thrown an error unless I cast s to an Account

However, I can assign a list of sobjects to a list of accounts

List<SObject> sList = new List<sObject>();
List<Account> aList = sList;

Again, why is this possible? Shouldn't we need to cast sList to List?

Best Answer

The question answer you linked was for when Key in Map was String, if its id then

Even the first one is allowed. Conversion of generic Sobject to the proper object

Account acc = new Account(Id='0014H00002LlXAj');
Map<Id,SObject> sobjectById = new Map<Id,SObject>();
sobjectById.put(acc.Id,acc);

Map<Id,Account> accountById = new Map<Id,Account>((List<Account>) sobjectById.values());