For a interface such as
public interface something<T>
{
public something<T> somemethod();
}
from what i understand the abstract method somemethod() needs to overridden with a method that returns an object implementing the interface. However, any attempts to do so have given me the "does not override the abstract method somemethod()" compiler error.
I've tried doing something like
public class someclass {
...
public something<T> somemethod() { ... return new someclass(); }
...
or
public someclass somemethod() { ... return new someclass(); }
...
}
How exactly would i implement such a method?
You're missing the generic declaration in your implementing class. Here's an example:
public interface Something <T> {
public Something<T> someMethod();
}
class SomethingImplementation <T> implements Something <T> {
@Override
public Something<T> someMethod() {
return null;
}
}
All of these should compile:
class test<T> implements something<T>{
public something<T> somemethod(){
return new test<T>();
}
}
class test1<T> implements something<T>{
public test1<T> somemethod(){
return new test1<T>();
}
}
class test2 implements something<Integer>{
public something<Integer> somemethod(){
return new test2();
}
}
class test3 implements something<Integer>{
public test3 somemethod(){
return new test3();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With