Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > names from Class.getName()

Reply
Thread Tools

names from Class.getName()

 
 
Rico
Guest
Posts: n/a
 
      11-28-2003
The following is my attempt at a sample program to illustrate my situation
but... well... things turn out to work fine here. that's not good! :S
--------------------------------------------------------------------------
class A
{
A()
{
b_here = new B();
}

private B b_here;

public B getB()
{
return b_here;
}
}

class B {}

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

private class D
{
D()
{
System.out.println(a_main.getB().getClass().getNam e());
}
}

A a_main;
public static void main(String [] args)
{
a_main = new A();
new C().new D();
}
}
-------------------------------------------------------------------------
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.

Rico.
 
Reply With Quote
 
 
 
 
Mattia Belletti
Guest
Posts: n/a
 
      11-28-2003
Rico wrote:
> The following is my attempt at a sample program to illustrate my situation
> but... well... things turn out to work fine here. that's not good! :S
> --------------------------------------------------------------------------
> class B {}
> [CUT]
> class C
> {
> C()
> {
> a_main = new A();
> }
>
> private class D
> {
> D()
> {
> System.out.println(a_main.getB().getClass().getNam e());
> }
> }
>
> A a_main;
> public static void main(String [] args)
> {
> a_main = new A();


You cannot access non-static a_main from a static context.

> new C().new D();
> }
> }
> -------------------------------------------------------------------------
> 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.


I've compiled and run, and prints "B".

--
/**
* Mattia Belletti - Undergraduate student @ cs.unibo.it
* ICQ: 33292311 - email: http://www.velocityreviews.com/forums/(E-Mail Removed)
* IRC: BluShine - site(s): http://cs.unibo.it/~mbellett
* Linux registered user 299762 @ Linux registered machine 213003
*/

 
Reply With Quote
 
 
 
 
Joana
Guest
Posts: n/a
 
      11-28-2003
hello,

> A a_main;
> public static void main(String [] args)
> {
> a_main = new A();

this is wrong.Compiler will show an error! Because a_main isn't static
and main-function is static.

This :
public static void main(String [] args)
{
// a_main = new A();
new C().new D();
}

gives output B.

regards,
joana




> -------------------------------------------------------------------------
> 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.
>
> Rico.

 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a
 
      11-30-2003
Rico <(E-Mail Removed)> said:
>The following is my attempt at a sample program to illustrate my situation
>but... well... things turn out to work fine here. that's not good! :S

....
>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]'.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      12-01-2003
Juha Laiho wrote:
> Rico <(E-Mail Removed)> said:
> >The following is my attempt at a sample program to illustrate my situation
> >but... well... things turn out to work fine here. that's not good! :S

> ...
> >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]'.


That would be accurate for anonymous inner classes. Static nested
classes would be given names built from the actual name of the nested
class as well as the containing class. As for "static inner classes",
no such thing exists; the static keyword is used to prevent a nested
class from being an inner class.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting 'flat' gate level names to hierarchical names Paddy McCarthy VHDL 3 09-24-2004 05:34 PM
table field names vs. display names Bob ASP .Net 1 07-30-2004 05:06 PM
Matching attribute names to element names in a different path Carl XML 0 04-01-2004 01:15 PM
WSDL- Mapping Application Defined Names to XML Names Craig XML 0 02-09-2004 04:14 PM
XSL rules applying to XSD (XML schema) defined type names (as opposed to node names) Lewis G. Pringle, Jr. XML 0 09-30-2003 10:34 PM



Advertisments