I have the following interface:
public interface Box<T> {
T get();
}
I'd like to be able to define another interface which is has Box<SomeType> as a parameter but for that interface to "know" what SomeType is.
e.g. I'd like to define the following interface
// this doesn't compile
public interface BiggerBox<B extends Box<H>> {
H get();
}
The idea being you could do something like this:
BiggerBox<Box<String>> biggerBox = new SomeBiggerBox(new SomeBox("some string"));
String value = biggerBox.get();
The closest thing I can get to is:
public interface BiggerBox<B extends Box> {
<U> U get();
}
But this has no compile-time type safety.
I think this is not possible in Java, but I would like to know if it is at all (even via mad hacks).
Edit: I don't want to add a second type parameter to the interface, i.e. no BiggerBox<Box<String>, String> (this is why I believe it's not possible)