Static Methods Inheritance

I want to use a Parent class called Settings, and this class is never used, it got some methods and one of the method is
public static NamespacedKey getKey() {
return null;
}
public static NamespacedKey getKey() {
return null;
}
I want that in the class that I am extending, to put the method again but with the class's key
public class MysticBossBarShow extends Settings {
private static final NamespacedKey key = new NamespacedKey(MysticEnchantments.getInstance(), "mystic_boss_bar_show");

public static NamespacedKey getKey() {
return key;
}
}
public class MysticBossBarShow extends Settings {
private static final NamespacedKey key = new NamespacedKey(MysticEnchantments.getInstance(), "mystic_boss_bar_show");

public static NamespacedKey getKey() {
return key;
}
}
so when I use MysticBossBarShow.getValue(player) - This methods uses getKey(), will it use the getKey() from the parent or from the child?
3 Replies
JavaBot
JavaBot5mo ago
This post has been reserved for your question.
Hey @MDT 168! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant 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.
MDT 168
MDT 168OP5mo ago
public static boolean getValue(Player player) {
if (getKey() == null) illegalUse();
return player.getPersistentDataContainer().getOrDefault(getKey(), PersistentDataType.BOOLEAN, true);
}
public static boolean getValue(Player player) {
if (getKey() == null) illegalUse();
return player.getPersistentDataContainer().getOrDefault(getKey(), PersistentDataType.BOOLEAN, true);
}
This is the getValue() in the parent Settings
JavaBot
JavaBot5mo ago
Post Closed
This post has been closed by <@1021759889623756852>.

Did you find this page helpful?