Other |
---|
tbdUnresolved |
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
JDK-8044629 changed the behavior so that Constructor.getAnnotatedReceiverType() does not return bogus non-null values. But it seems it is a little overzealous. For local classes of non-static methods, there is a receiver type (as demonstrated by the constructors below), and so getAnnotatedReceiverType should not return null. Or perhaps javac and core reflection disagree? Try running the demo program below with jdk8 and jdk9: In jdk8 we get the correct output: receiver type=sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl@6d06d69c receiver type=sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl@7852e922 In jdk9 we get: receiver type=null receiver type=sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl@5f375618 /* * Copyright 2016 Google Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.lang.reflect.Constructor; public class ReceiverType { public static void main(String[] args) throws Throwable { new ReceiverType().instanceMain(); } class Member { Member(ReceiverType ReceiverType.this) {} } public void instanceMain() throws Throwable { class Local { Local(ReceiverType ReceiverType.this) {} } printConstructor(Local.class); printConstructor(Member.class); } static void printConstructor(Class<?> klazz) { Constructor<?>[] constructors = klazz.getDeclaredConstructors(); if (constructors.length != 1) throw new AssertionError(); System.out.printf("receiver type=%s%n", constructors[0].getAnnotatedReceiverType()); } }
|