This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes name conflict Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "name conflict" Watch "name conflict" New topic
Author

name conflict

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787

Why no error for line 1 but line 2 does not compile....
Dan Lastoria
Ranch Hand

Joined: Jan 30, 2002
Posts: 57
In the statement System.out.println(Test.Test) The compiler will access the type "Test" based on the nearest scope. In your case "Test" references the primitive int static field. So what you're trying to do is like saying "for the primitive static int field named Test give me member Test", which doesn't exist.
The compiler is not seeing Test.Test as "Class Test.Static Member Field Test". It is seeing it as "Static Member Field Test.No Such Member".
[ August 18, 2003: Message edited by: Dan Lastoria ]
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Thanks. I did not think it that way.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
I would like to have a go at explaining this, because I am not good at determining the meaning of a name. I need the practice.
System.out.println(Test.Test);
1. The name �Test.Test� does not exist in a context (JLS 6.5.1) where it is clearly a package name, type name, expression name, method name or package or type name. So it is classified as an ambiguous name.
2. Then the ambiguous name �Test.Test� is reclassified (JLS 6.5.2). Since it is a qualified name, the name to the left of the dot �Test� is reclassified. This name does not exist in a context (JLS 6.5.1) where it is clearly a package name, type name, expression name, method name or package or type name. So it is classified as an ambiguous name.
3. Then the ambiguous name �Test� is reclassified (JLS 6.5.2). Since it is a simple name, and it appears within the scope of a local variable declaration (no) or parameter declaration (no) or field declaration (yes) with that name, it is reclassified as an expression name.
4. Now that �Test� to the left of the dot has been classified as an expression name (i.e. an identifier of a field declaration), the name to the right of the dot must be a member of the type of that field. But the type of that field is a primitive int.
So we get the compiler error : int cannot be dereferenced
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: name conflict
 
Similar Threads
assignment operator
interface question
Resolve.........
instanceof Doubt again??
about null