Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Name mangling
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Java === In [[Java (programming language)|Java]], the ''signature'' of a method or a class contains its name and the types of its method arguments and return value, where applicable. The format of signatures is documented, as the language, compiler, and .class file format were all designed together (and had object-orientation and universal interoperability in mind from the start). ====Creating unique names for inner and anonymous classes==== The scope of anonymous classes is confined to their parent class, so the compiler must produce a "qualified" public name for the [[inner class]], to avoid conflict where other classes with the same name (inner or not) exist in the same namespace. Similarly, anonymous classes must have "fake" public names generated for them (as the concept of anonymous classes only exists in the compiler, not the runtime). So, compiling the following Java program: <syntaxhighlight lang="java"> public class foo { class bar { public int x; } public void zark () { Object f = new Object () { public String toString() { return "hello"; } }; } } </syntaxhighlight> will produce three '''.class''' files: * '''foo.class''', containing the main (outer) class ''foo'' * '''foo$bar.class''', containing the named inner class ''foo.bar'' * '''foo$1.class''', containing the anonymous inner class (local to method ''foo.zark'') All of these class names are valid (as $ symbols are permitted in the JVM specification) and these names are "safe" for the compiler to generate, as the Java language definition advises not to use $ symbols in normal java class definitions. Name resolution in Java is further complicated at runtime, as [[fully qualified name]]s for classes are unique only inside a specific [[classloader]] instance. Classloaders are ordered hierarchically and each Thread in the JVM has a so-called context class loader, so in cases where two different classloader instances contain classes with the same name, the system first tries to load the class using the root (or system) classloader and then goes down the hierarchy to the context class loader. ====Java Native Interface==== [[Java Native Interface]], Java's native method support, allows Java language programs to call out to programs written in another language (usually C or C++). There are two name-resolution concerns here, neither of which is implemented in a [[Technical standard|standardized]] manner: * JVM to native name translation - this seems to be more stable, since Oracle makes its scheme public.<ref>{{cite web |title=Design Overview |url=https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html |website=docs.oracle.com}}</ref> * Normal C++ name mangling - see above.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)