About using Generic in enhanced enum

The generic part of the code:

enum Default<T extends Object> {
  font<String>('roboto'),
  size<double>(17.0),
  weight<int>(400);

  const Default(this.value);
  final T value;
}

And I find that it works completely well with the following:

enum Default<T> {
  font<String>('roboto'),
  size<double>(17.0),
  weight<int>(400);

  const Default(this.value);
  final T value;
}

What is the difference between enum Default<T extends Object> and enum Default<T>? I actually don’t find a valid reason why it needs to extends Object.

1 Like

I feel like when I was writing this chapter, there was some kind of error when I didn’t extend Object. I’m wondering if Dart 2.19 improved how this worked. Or maybe I just added needless code for no reason in the first place. Anyway, like you, I also don’t see any reason to extend Object anymore. Let’s remove that in the next edition. Thank you.

2 Likes