Skip to content

Instantly share code, notes, and snippets.

@adibfara
Created October 18, 2023 08:52
Show Gist options
  • Save adibfara/790ce2af1a18798e820a5b8600ff03de to your computer and use it in GitHub Desktop.
Save adibfara/790ce2af1a18798e820a5b8600ff03de to your computer and use it in GitHub Desktop.
No Visitor
public record Box(int size) implements Item {}
public record Container(Item[] items) implements Item { }
public class WeightCalculator {
public int calculate(Box box) {
return box.size();
}
public int calculate(Container container) {
int sum = 2;
for (Item item : container.items()) {
sum += calculate(item); // [!] Cannot resolve method 'calculate(Item)'
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment