Let's say we have some interface like this:
public interface Foo<T> {
<TIn extends T> void encode(TIn value)
T decode()
}
I'm using Foo a lot in my codebase, but I wish to add the TIn extends T to make it more flexible, to eg have a Foo<Map<X>> able to encode a HashMap<X> or a TreeMap<X>.
This works really well - until I tried to implement Foo<T[]>, where it seems to be impossible to implement, with public <TIn extends TItem[]> void encode(TIn array) giving a parse error "> expected" when it hits the brackets []. Even IntelliJ does nothing when it volunteers to implement the interface.
For what it's worth, if T is some other concrete final type (eg byte[], Boolean, etc), it seems that I can satisfy the interface by just returning T, so it seems to do some hidden intelligent fixing here. So it seems that it's just a problem with T[] where it can't detect T[] is final.
Does anyone have any ideas about how I can workaround this? I don't really care that TIn extends byte[] can only be met with TIn = byte[], I just want to implement the interface for the compiler to be happy; and so that this interface can be used elsewhere.