RFR (S): JDK-8039916: AnnotatedType.getType() of a Executable parameters may return wrong type

Remi Forax forax at univ-mlv.fr
Wed Jun 4 15:06:48 UTC 2014

On 06/04/2014 12:34 PM, Paul Sandoz wrote:
> On Jun 4, 2014, at 12:25 PM, Paul Sandoz <Paul.Sandoz at oracle.com> wrote:
>> You might consider the following a more streamy way, not tested! up to you :-)
>>     private static Object[][] provider() {
>>         Stream<? extends Executable> s = filterData(Test.class.getMethods(), null);
>>         s = Stream.concat(s, filterData(Test.class.getConstructors(), null));
>>         s = Stream.concat(s, filterData(Test.class.getConstructors(), null));
>>         return streamToArray(s);
>>     }
>>     private static Stream<? extends Executable> filterData(Executable[] es, Class<?> c) {
>>         return Stream.of(es).filter(m -> m.getDeclaringClass() == c);
>>     }
> Plus you can drop the "? extends" bit of "? extends Executable", that was a hangover from some other mini experiment.

returning a Foo<? extends XXX> is usually a design error (apart from 
covariant return type in case of overriding but usually it's because the 
API was designed before the introduction of generics), because all 
client codes will have to declare a Foo<? extends XXX>.
Here, it's better to introduce a type variable

     private static <E extends Executable> Stream<E> filterData(E[] es, Class<?> c) {
        return Stream.of(es).filter(m -> m.getDeclaringClass() == c);

> Paul.


More information about the core-libs-dev mailing list