question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hashCode generator enhancement

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bwilkersoncommented, Aug 28, 2020

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 use hashValues.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found