Blog

[Dart] Overriding hash for Your Own Objects

Published 1 min read

class Medicine { final String itemName; // 제품명 final String entpName; // 업체명 final int count; @override bool operator==(Object other) => other is Medicine && itemName == other.itemName; @override int get hashCode => Object.hash(itemName, entpName); }

For hashCode you can use Object.hash
Even if count is different, as long as itemNamer and entpName are the same, they're treated as the same object

Comments

Leaving a comment stores your nickname (or GitHub profile info). Privacy policy

GitHub