Re: Names from Class.getName()

Discussion in 'Java' started by Rico, Dec 1, 2003.

  1. Rico

    Rico Guest

    On Sun, 30 Nov 2003 15:46:59 +0000, Juha Laiho wrote:
    > Rico <> said:
    >>In my project what I'm observing is that from class D's constructor what's
    >>printed out is not "B" but something like "A$1"...
    >>Anyone with some idea as to why? Thanks.

    >
    > Looks like ..hmm.. static inner class. Is in your project 'B' a static
    > class contained within 'A'? If so, it becomes to a toplevel class with
    > name 'A$[number]'.


    thanks a lot for the tip Juha. But even the following doesn't give
    'A$[<number>]'. Just 'A$E' ... Actually, in my project 'E' is not a static
    class.

    class A
    {
    class E
    {

    }

    A()
    {
    b_here = new E();
    }

    private static E b_here;

    public E getB_here()
    {
    return b_here;
    }
    }

    public class C
    {
    C()
    {
    a_main = new A();
    }

    private class D
    {
    D()
    {
    System.out.println(a_main.getB_here().getClass().getName());
    }
    }

    A a_main;
    public static void main(String [] args)
    {
    new C().new D();
    }
    }
    Rico, Dec 1, 2003
    #1
    1. Advertising

  2. Inner class naming is "<outer_class>$<inner_class>" or,
    for anonymous inner classes "<outer_class>$<n>"
    where "<n>" is a decimal (?) number, starting from 1.
    Thomas Schodt, Dec 1, 2003
    #2
    1. Advertising

  3. Rico

    Rico Guest

    On Mon, 01 Dec 2003 11:14:27 +0000, Thomas Schodt wrote:
    > Inner class naming is "<outer_class>$<inner_class>" or,
    > for anonymous inner classes "<outer_class>$<n>"
    > where "<n>" is a decimal (?) number, starting from 1.


    Thank You Thomas. That, as well as Juha's, was a helpful hint though.
    Here's what I had that was causing this:

    class A
    {
    A()
    {
    b_here = new B() {
    protected void removeRedundant()
    {
    slaughter();
    }
    };
    }
    }

    // b_here.getClass().getName() gave 'A$1'

    How's this one called again? a method call bundled with the constructor...

    Rico.
    Rico, Dec 2, 2003
    #3
  4. Rico

    Chris Smith Guest

    Rico wrote:
    > Thank You Thomas. That, as well as Juha's, was a helpful hint though.
    > Here's what I had that was causing this:
    >
    > class A
    > {
    > A()
    > {
    > b_here = new B() {
    > protected void removeRedundant()
    > {
    > slaughter();
    > }
    > };
    > }
    > }
    >
    > // b_here.getClass().getName() gave 'A$1'
    >
    > How's this one called again? a method call bundled with the constructor...


    That's an anonymous inner class.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Dec 2, 2003
    #4
  5. Chris Smith wrote:
    >>How's this one called again? a method call bundled with the constructor...

    >
    >
    > That's an anonymous inner class.


    And it's not a method call, it's a method *definition*.
    Michael Borgwardt, Dec 2, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    1
    Views:
    8,291
    Paul Tomblin
    Jun 27, 2003
  2. Rico
    Replies:
    4
    Views:
    401
    Chris Smith
    Dec 1, 2003
  3. Robert Mark Bram

    class.getName()

    Robert Mark Bram, Jun 17, 2004, in forum: Java
    Replies:
    8
    Views:
    4,076
    Jeff Robertson
    Jun 18, 2004
  4. Replies:
    1
    Views:
    446
    John C. Bollinger
    May 2, 2005
  5. WT
    Replies:
    6
    Views:
    924
    Walter Wang [MSFT]
    May 18, 2006
Loading...

Share This Page