JDK-8057919 Class.getSimpleName() should work for non-JLS compliant class names

joe darcy joe.darcy at oracle.com
Tue Jun 16 18:48:53 UTC 2015


FYI,

     "Nested, Inner, Member, and Top-Level Classes"
     https://blogs.oracle.com/darcy/entry/nested_inner_member_and_top

-Joe

On 6/16/2015 1:40 AM, Vladimir Ivanov wrote:
> Jochen,
>
> Let me elaborate on that topic a bit.
>
> There are 5 types of classes mentioned in JVMS:
>   - top-level
>   - nested
>   - inner
>   - local
>   - anonymous
>
> Example:
> class TopLevel {
>   static class Nested {}
>   class        Inner  {}
>
>   void f() {
>     class Local {}
>   }
>   Object o = new TopLevel() {}; // anonymous
> }
>
> And here's how they look like on bytecode level.
>
> I'll use both javap and ASM to dump class structure:
>   $ java jdk.internal.org.objectweb.asm.util.ASMifier <class_file>
>
> Nested:
>   javap: static #11= #10 of #5; //Nested=class TopLevel$Nested of 
> class TopLevel
>   asm: cw.visitInnerClass("TopLevel$Nested", "TopLevel", "Nested", 
> ACC_STATIC);
>
> Inner:
>   javap: #8= #7 of #5; //Inner=class TopLevel$Inner of class TopLevel
>   asm: cw.visitInnerClass("TopLevel$Inner", "TopLevel", "Inner", 0);
>
> Local:
>   javap: #13= #12; //Local=class TopLevel$1Local
>   asm: cw.visitInnerClass("TopLevel$1Local", null, "Local", 0);
>
> Anonymous:
>   javap: #2; //class TopLevel$1
>   asm: cw.visitInnerClass("TopLevel$1", null, null, 0);
>
> TopLevel.class contains all aforementioned attributes.
>
> Best regards,
> Vladimir Ivanov
>
> On 6/16/15 7:29 AM, Jochen Theodorou wrote:
>> Am 15.06.2015 18:04, schrieb Vladimir Ivanov:
>> [...]
>>> In order to make the class non-anonymous again, you have to specify
>>> inner_name_index and, optionally, outer_class_info_index.
>>
>> ok... let me try to understand this better... taking this Java source
>>
>>> public class Test {
>>> public static void main(String[] args) {
>>>   class X{}
>>>   Runnable foo = new Runnable(){public void run(){}};
>>> }}
>>
>> I get for Test
>>
>>> InnerClasses:
>>>      static #2; //class Test$1
>>>      #12= #11; //X=class Test$1X
>>
>> Is it the #12=#11 part which tells me X is no anonymous class? Is #11
>> the inner_name_index?
>>
>> bye Jochen
>>




More information about the core-libs-dev mailing list