所以我有一个arrayList
Dog spot = new Dog("Spot", "Lab","Blonde", Tail.OTTER,"Yes", 50, 3);
Dog buddy = new Dog("Buddy", "Pit Bull", "Black", Tail.DOCKED,"Yes", 60, 2);
Dog mia = new Dog ("Mia", "Pug", "Brown", Tail.RING ,"No", 70, 4);
现在 50、60 和 70 是狗的重量。我想在不写出冗长、不灵活的代码的情况下将它们加起来,例如:
int totalWeight = spot.weight + buddy.weight + mia.weight;
有没有办法做到这一点?