spacer
Yehuda Shiran May 26, 2002
Handling Non-Qualified Name Collisions
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

When you import classes from outside your code, there is always a possibility of class and variable collisions, if you use non-qualified names. Non-qualified names sometimes do not uniquely identify a class or a class member, because these classes are defined in multiple namespaces. In such cases of ambiguity, the local class takes over the imported class. The following USA.Florida namespace defines the class Head, which includes the Governor function:

  package USA.Florida {
    public class Head {
      static var Governor : String = "Bush";
    }
  };
The following code defines a local class and a local function. They are named by the same names as above:

   class Head {
      static var Governor : String = "Davis";
   }
Now, we import USA.Florida, conflicting the definition of Head and Governor:

  import USA.Florida;
The class Head.Governor is non-qualified, because there is such a class in the USA.Florida namespace, and there is also a class by the same name in the local namespace. When you print the value of the non-qualified function Head.Governor, the local value will override the imported name. The code:

  print(Head.Governor);
will yield the following output:

  Davis
To learn more about JScript .NET, go to Column 109, JScript .NET, Part III: Classes and Namespaces.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business