hashCode generator enhancement
See original GitHub issueWhen the built-in generator (ALT + Insert on Windows) is used for example in model classes, we can use it for generating ==, hashCode and toString() methods.
Let’s say we have this model class:
class Example {
const Example({
this.category,
this.id,
this.isFavorite,
this.name,
this.price,
this.startDate,
this.expirationDate,
});
final Category category;
final int id;
final bool isFavorite;
final String name;
final int price;
final DateTime startDate;
final DateTime expirationDate;
}
Generated hashCode method for this example is:
@override
int get hashCode =>
category.hashCode ^
id.hashCode ^
isFavorite.hashCode ^
name.hashCode ^
price.hashCode ^
startDate.hashCode ^
expirationDate.hashCode;
Instead, I think it would be better if it was generating this using hashValues (if it would have more than 1 argument and less than 20)
@override
int get hashCode => hashValues(category, id, isFavorite, name, price, startDate, expirationDate);
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Guide to hashCode() in Java - Baeldung
Generate equals() and hashCode() with Eclipse ... Java 8 brought an interesting enhancement to HashMap implementation.
Read more >python - LSH hashcode generator function
Yet the resulting time difference is marginal, therefore no real improvement. Using your timing comparison, the result is:
Read more >Secure Hash Generator - WebBrowserTools
Secure Hash Generator. Generate a secure hashcode (i.e. checksum) for any file or string via an easy-to-use interface! Logo ...
Read more >AI Image Generator: Hash code - Neural Love
with Free AI Art Generator β. Simplest AI Art Generator with a built-in prompt generator. Created 65 days ago. Hash code. Painting, 4...
Read more >What is the best algorithm for overriding GetHashCode?
public override int GetHashCode() => HashCode.Combine(field1, field2, field3);. This will generate a quality hash code without you having to worry about the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://youtrack.jetbrains.com/issue/IDEA-249561
Yes, and when the new static methods in
Object
land, we should definitely update the generator to make use of them. Given how soon they will likely land, I don’t think it’s worth changing it to usehashValues
.