Hello,
I don't really understand what is the advantage of the interface SimpleObject<T>.
So in my example the class Cat implements the interface SimpleObject<T> with class parameter Cat.
The method getInstance() returns the reference to current class object.
Could sb please give me an example how can I use this method getInstance() later?
I can just create a new Cat() in the main method, so why I should use interface SimpleObject<T>?
Thank you :)
public class Interface5 {
public static void main(String[] args) throws Exception {
Cat cat= new Cat();
}
interface SimpleObject<T> {
SimpleObject<T> getInstance();
}
class StringObject implements SimpleObject<String>
{
public SimpleObject<String> getInstance(){
return this;
}
}
static class Cat implements SimpleObject<Cat>
{
public SimpleObject<Cat> getInstance(){
return this;
}
public String toString(){
return "cat";
}
}
}