Why does one error and not the other?

I am using Intellij, and it is completely fine with this code
@Override
void updateStats() {
this.armor = this.baseArmor;
this.power = this.basePower + this.weapon.power;
this.attackBonus = this.baseAttackBonus;
for (ToolItem t : equippedArmor) {
this.armor += t.armor;
}
for (ToolItem t : equippedTrinkets) {
this.attackBonus += t.bonus;
}
}
@Override
void updateStats() {
this.armor = this.baseArmor;
this.power = this.basePower + this.weapon.power;
this.attackBonus = this.baseAttackBonus;
for (ToolItem t : equippedArmor) {
this.armor += t.armor;
}
for (ToolItem t : equippedTrinkets) {
this.attackBonus += t.bonus;
}
}
but says this does not work, with the error "method does not override method from it's superclass."
@Override
void applyEffects(ArrayList<String> keys) {
for (String key: keys) {
switch (key) {
case "frozen" -> this.power = 0;
case "stuck" -> this.armor /= 2;
case "disarmed" -> this.power -= this.weapon.power;
case "disarmored" -> {
for (ToolItem i : this.equippedArmor) {
if (i != null) this.armor -= i.armor;
}
}
}
}
}
@Override
void applyEffects(ArrayList<String> keys) {
for (String key: keys) {
switch (key) {
case "frozen" -> this.power = 0;
case "stuck" -> this.armor /= 2;
case "disarmed" -> this.power -= this.weapon.power;
case "disarmored" -> {
for (ToolItem i : this.equippedArmor) {
if (i != null) this.armor -= i.armor;
}
}
}
}
}
Both of these methods are overriding equivalent methods from the class this one extends.
20 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @blockgoblin31! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
blockgoblin31
blockgoblin31OP2y ago
if anyone needs to see, the ones from the base class are
void applyEffects(ArrayList<String> keys) {
for (String key: keys) {
switch (key) {
case "frozen" -> this.power = 0;
case "stuck" -> this.armor /= 2;
default -> {

}
}
}
}

void updateStats() {
this.power = basePower;
this.armor = baseArmor;
this.attackBonus = baseAttackBonus;
}
void applyEffects(ArrayList<String> keys) {
for (String key: keys) {
switch (key) {
case "frozen" -> this.power = 0;
case "stuck" -> this.armor /= 2;
default -> {

}
}
}
}

void updateStats() {
this.power = basePower;
this.armor = baseArmor;
this.attackBonus = baseAttackBonus;
}
Kyo-chan
Kyo-chan2y ago
With what you describe, both should work. I guess we'd need the full context
blockgoblin31
blockgoblin31OP2y ago
this is all the additional info I have
No description
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
I dont know what any of those words mean...
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
the class definition is just public class Player extends Enemy {
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
thats what I think I have for both of those
Kyo-chan
Kyo-chan2y ago
You have the entire code Though only the start of each should be enough
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
fixed it, I did something dumb and got confused by it
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
effectively I have a class that extends ArrayList that I decided to name, for simplicities sake, ArrayList
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
the Enemy file was using that one, while the Player file was using the default one importing the custom one in the player file fixed the issue
Kyo-chan
Kyo-chan2y ago
renaming would be smart
blockgoblin31
blockgoblin31OP2y ago
yea, probably Ill go call it list quickly
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@501514065068294154>.
Want results from more Discord servers?
Add your server