I had a little problem a few times when I want to do something like this:
interface MyInterface
{
public Validator<this.class> getValidator();
}
class MyInstance implements MyInterface
{
public Validator<this.class> getValidator()
{
}
}
So, in order to be able to pass a reference to a specific class as a general parameter, this is often necessary if you have classes acting on the current class. Easy solution - use? type, but it is not ideal when you need to access values in the class itself (for example, if you need to do something like getValidator().validateForm().getField()) or even if you want to subclass the class using chain methods (for example, StringBuilder.append())
As usual, I had to do it like this:
interface MyInterface<T>
{
public Validator<T> getValidator();
}
class MyInstance implements MyInterface<MyInstance>
{
public Validator<MyInstance> getValidator()
{
}
}
but it's pretty ugly, and it's easy to accidentally put the wrong class as a parameter.
Are there any other solutions for this?
: , " ?" ( Scala)