Created
October 18, 2023 08:52
-
-
Save adibfara/790ce2af1a18798e820a5b8600ff03de to your computer and use it in GitHub Desktop.
No Visitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public record Box(int size) implements Item {} | |
public record Container(Item[] items) implements Item { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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