I’m trying to implement classes from the same interface but with a different number of parameters in method like the code below. Is there a way in Java to define methods in the interface without constraining the number of parameters? Answer You could use the ellipsis syntax (…) and then check the number of arguments passed to the method in
Tag: overriding
How to properly add a value change listener to Map.Entry?
A project im working on currently requires me to ensure that while looping through a map’s entries, if Entry.setValue is called, it would trigger a value change event. I see I can try something like …
Java override non abstract method as abstract in extended class
So I have a non-abstract method onStop inside the base class. Is it acceptable to make it abstract in the extented MyTask? The aim is to force the onStop to be implemented by classes that extend the …
Java create method in Interface and change the parameter type
How do I create an interface that when Overridden can have different types? Sometimes I would like the method to accept an item of type ‘HtmlPage’ and other times I would like it to take the type ‘Document’. Later these could change to even more types. Example: I am thinking something like this should be achievable. I have tried looking
Java: Calling a super method which calls an overridden method
public class SuperClass { public void method1() { System.out.println(“superclass method1”); this.method2(); } public void method2() { System.out.println(“…
Calling super super class method
Let’s say I have three classes A, B and C. B extends A C extends B All have a public void foo() method defined. Now from C’s foo() method I want to invoke A’s foo() method (NOT its parent B’s …