Type of Class

Brian Goetz brian.goetz at oracle.com
Fri Feb 21 15:40:08 UTC 2014


I understand why you want this, though I think you’ll find that there are still thousands of other things “missing” from reflection.  

In the Java 1.0 days, the difference between the Java language and the class file was pretty small.  So reflection served as both the class file (VM) reflection and language reflection mechanism.  But, over time, the gap has grown wider.  We’ve made the decision (though not always consistently applied) that reflection is about serving up the class file information to Java, not about answering questions about the Java language.  So, for example, it can’t tell that one method is a bridge for another, or easily answer questions about inheritance or overriding.  Similarly, the issues raised here are about gaps between the class file representation of a class and the language level model.  

Historically we have added some things to reflection to fill in these gaps.  However, our current strategy is to expose this through javax.lang.model, which is designed to reflect the langauge-level view of the world, and this is what users really want anyway.  Currently the only implementation of javax.lang.model that is available is in the compiler, exposed to annotation processors, but we have a plan to expose one backed by core reflection which is a more sensible way to express the information you are looking for.  


On Feb 21, 2014, at 2:27 AM, Stephen Colebourne <scolebourne at joda.org> wrote:

> On 21 February 2014 08:14, David Holmes <david.holmes at oracle.com> wrote:
>>> Would it be reasonable to add the following methods:
>>> - isNestedClass()
>> This would be !isTopLevelClass() but otherwise
>> isAnonymousClass() || isLocalClass() || isMemberClass()
>>> - isInnerClass()
>> isAnonymousClass() || isLocalClass() || (isMemberClass() && !static)
>>> - isTopLevelClass()
>> ! (isAnonymousClass() || isLocalClass() || isMemberClass())
>> and for completeness:
>> - isStaticNestedClass() == isMemberClass() && static
> 
> I think the next step is a JIRA unless anyone objects.
> Stephen




More information about the core-libs-dev mailing list