With the following method definition:
protected <T extends Enum<T>> Tuple4< Boolean, String, T, String> foo( T... args ) {
...
}
(that is, a method that accepts any kind of Enum as argument, uses it internally and returns an instance of this class)
and using it as:
protected String bar( Enum<?>... args ) {
...
foo( args );
...
compiler complains:
error: method foo in class xxxx cannot be applied to given types;
However, if I change "foo" declaration, using Enum instead of Enum as in:
protected <T extends Enum<?>> Tuple4< Boolean, String, T, String> foo( T... args ) {
...
}
everything compiles ok.
I do not understand the origin of the first error and which is the best way to write this code.
Which difference there are in use at "foo" the term "<T extends Enum<T>>" (something recursive that always cause me some doubts) or use "<T extends Enum<?>>" ?
(note: assume "bar" implementation can be changed but its declaration can not be changed).
argspassed tofooare defined in terms ofEnum<?>and notEnum<T>