Check Map data types in generics

Solution 1:

The problem with E is Map is that the is operator is True if the object has the specified type, but the type of E is actually not E but rather type Type.

if (E is Type) {
  print('Type!!!');
}

The problem with E == Map is that Map is a raw type which is equivalent to Map<dynamic, dynamic>. If E is any other type of Map you will get false.

What you can do is check the type of an instance of E rather than E itself. For example, something like:

void add(E element) {
  if (element is Map) {
    print('Map!!');
  }
}