Incorrect ClassDoc for nested classes

Hello,
I think there is a bug in Javadoc concerning nested classes ClassDoc records extracted through the doclet API.
In particular, ClassDoc records are correct if the container class is directly specified on the command line as a .java file or part of a package (i.e. the source is available), but they are (at times) wrong if the records are built from .jar (.class) files through the classpath.
Example with "java.io.ObjectOutputStream" from JDK 1.3.1_01:
If the ClassDoc for this class comes from RootDoc.specifiedClasses(), its nested classes are correctly listed as:
private static final class java.io.ObjectOutputStream.HandleTable
public abstract static class java.io.ObjectOutputStream.PutField
static final class java.io.ObjectOutputStream.PutFieldImpl
private static final class java.io.ObjectOutputStream.ReplaceTable
private static final class java.io.ObjectOutputStream.Stack
but if the ClassDoc of the container class is extracted from a method parameter, like in org.apache.xerces.dom.ParentNode.writeObject(ObjectOutputStream out), this is the result:
final synchronized class java.io.ObjectOutputStream$HandleTable
public abstract static class java.io.ObjectOutputStream.PutField
static final class java.io.ObjectOutputStream.PutFieldImpl
final synchronized class java.io.ObjectOutputStream$ReplaceTable
final synchronized class java.io.ObjectOutputStream$Stack
According to my tests, at least ClassDoc.modifiers(), ClassDoc.qualifiedName() and ClassDoc.containingClass() return incorrect results for HandleTable, ReplaceTable and Stack.
This behaviour seems common to both Javadoc 1.3.1_01 and 1.4beta3. I admit I didn't test 1.4 final, but I searched the Javadoc site, the forum and the bug database without finding anything similar.
Thanks in advance for any help.
Amedeo Farello

Thank you for looking into this.
This is beyond my understanding of the Doclet API.
Please submit this as a bug using the instructions at:
http://java.sun.com/j2se/javadoc/faq/index.html#submitbugs
and please email the ID number you get back to me
at [email protected] so I can make sure it gets
past our initial reviewers and into our bug database so
our javadoc engineer can look at it.
-Doug Kramer
Javadoc team

Similar Messages

  • Signature for nested class?

    Hi all,
    I'm trying to use JNI on WindowsXP, java version:
    java version "1.6.0_13"
    Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
    Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)
    When trying to get jclass for a nested class
    jclass c = env->FindClass ("A$B");
    assert (c);
    the second line asserts, The same thing works ok on Linux with slightly different version of Java (1.5... IIRC).
    I've tried several permutations like
    LA$B;
    A.B
    LA.B;
    but to no avail.
    Any advice will be highly appreciated.
    Martin

    jschell wrote:
    Myself I usually use "javap -c" with some temp code since the output of that is almost exactly correct (I think there is a one character substition.)Ok, here's what I've found:
    Definition of the class:
    public class A
    // the nested class
    public static class B {
    // function returning the nested class
    public native B fx ();
    The nested class is mentioned at a single place in the output from the javap -c A:
    public native A$B fx();
    Now, the native code correctly retrieves field IDs of properties of A (thus is seems that it has access to the metadata), then it tries to retrieve jclass for B:
    jclass idc = env->FindClass ("A$B");
    assert (idc); // fails here
    the second line asserts, The same thing works ok on Linux with slightly different version of Java (1.5... IIRC).Names are the same. So that means the environment is not the same. If that function returns an error (thus the assert) it means a java exception exists which you can print. But it probably just means that the class wasn't found. And that means the class path is wrong or you are missing the class.See above, the code is able to get metadata for the outer class' properties (A), thus the class path must be correct.
    One idea: FindClass is called within A's constructor. Isn't it possible that the nested classes are registered on the fly after the outer class' constructor succeeds? Maybe the relevant code have changed between 1.5 and 1.6? Maybe it works that way on Win32, but not on Linux?
    Thoughts? Is it a bug in Java? Should it be reported?
    Martin

  • Internal Nested Classes

    How does access control work for nested classes? For example
    public class A  {
    public class B {
        private int c;
        private B() {
    }how does A refer to private members of B?

    B b = new B();
    b.c = 123;[url http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.1]JLS 6.6.1 Determining Accessibility
    "...if the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor. "
    In other words anything that's declared private anywhere inside the top-level public class A { ... } is accessible anywhere else inside public class A { ... }

  • Nested Subpanels for LVOOP Class Hierarchy

    Hi,
    I am trying to figure out a way to create a configuration window for a class object using a subpanel. The problem is that I have LVOOP class hierarchy of 3 levels, and thus I want to use nested subpanels, one subpanel for each inheritance.
    For example, 
    A.lvclass (abstract class)
    Private Data Members
     String A
    Configuration Window VI ( Within a FP there is a String A control and a subpanel for its child class)
    B.lvclass (abstract class) (child of A.lvclass)
    Private Data Members
    Boolean A
    Boolean B
    Configuration Window VI (Within the FP there is a Boolean A control and a Boolean B control, plus a subpanel for its child class)
    C1.lvclass (concrete class) (child of B.lvclass)
    Private Data Members
    File Path A
    Configuration Window VI (Within the FP there is a File Path A control)
    C2.lvclass (concrete class) (child of B.lvclass)
    Private Data Members
    Boolean C
    Configuration Window VI (Within the FP there is a Boolean C control)
    What I am trying to accomplish is to create configuration windows for C1 and C2. For each configration window, there are sections for class A and class B, and for the class itself. However, I do not want to recreate the same section (for A and B) over and over again each time new children (siblings of C1) are introduced. To avoid this duplicate task, I think using nested supanes makes sense. But I don't know the best way to do it. Any advice is appreciated
    Thank you
    TailOfGon
    Certified LabVIEW Architect 2013

    See these two threads and be sure to read them thoroughly and follow the links:
    http://forums.ni.com/t5/LabVIEW/An-experiment-in-c​reating-compositable-user-interfaces-for/m-p/12623​...
    http://forums.ni.com/t5/LabVIEW/A-more-successful-​experiment-in-creating-compositable-user/m-p/12768​...
    Try to take over the world!

  • Are static nested classes thread-safe?

    There doesn't seem to be any definitive answer to this. Given the following code, is it thread-safe?
    public class SomeMultiThreadedWebController {
    public HttpServletResponse someMethodToExecuteViaWebRequest(HttpServletRequest request) {
        simpleQueryBuilder("SELECT...").addParameter("asdf","asdf").createQuery(EMF.getEntityManager()).executeUpdate();
    protected static class SimpleQueryBuilder {
             private String queryString;
             private Map<String, Object> params = new HashMap<String, Object>();
             public SimpleQueryBuilder(String queryString) {
                  this.queryString = queryString;
             public SimpleQueryBuilder addParameter(String name, Object value) {
                  params.put(name, value);
                  return this;
             public Query createQuery(EntityManager em) {
                  Query query = em.createQuery(queryString);
                  for (Entry<String, Object> entry : params.entrySet()) {
                       query.setParameter(entry.getKey(), entry.getValue());
                  return query;
        public static SimpleQueryBuilder simpleQueryBuilder(String queryString) {
             return new SimpleQueryBuilder(queryString);
    }Forget whether or not someone would do this, as this is just an example. I'm really trying to get at whether or not the instance variables inside the static nested class are thread-safe. Thanks for any responses.

    Hello,
    I believe you understand what you're talking about, but you state it in a way that is very confusing for others.
    Let me correct this (essentially, incorrect uses of the terminology):
    I agree that thread-safe or not is for an operation, for a member, it has some sort of contextual confusion.
    Member has a much broader meaning in the [Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.4] . Even "class member" applies to both an attribute, a method, or an inner class or interface.
    I think you mean "member variable" of a class (aka "attribute" or "field"). By the way, static or not is irrelevant to the rest of the discussion.
    For an operation or a member, if there's only one thread could access it atomically in one moment, we could call it thread-safe.Mmm. I was tempted to say yes (I'm reluctant to commit myself). With an emphasis on "_The encapsulating class_ makes this member's usage thread-safe".
    Still, just synchronizing each operation on a member is not enough to make all usages "thread-safe":
    Consider a java.util.Vector: each add/get is synchronized, so it is atomic, fine.
    However if one thread adds several values, let's say 3, one by one, to a vector that initially contains 0 values, and another thread reads the vector's size() (another properly synchronized method), the reader thread may witness a size anywhere among 0, 1, 2, 3, which, depending on the business logic, may be a severely inconsistent state.
    The client code would have to make extra work (e.g. synchronizing on the vector's reference before the 3 adds) to guarantee that the usage is thread-safe.
    Thus any synchronized method(With the limit stated above)
    or immutable member (like primitive type) are thread-safe.
    Additionally for a member, if it's immutable, then it's thread-safe. You mean, immutable primitive type, or immutable object. As stated previously, an immutable reference to a mutable object isn't thread-safe.
    a static final HashMap still have thread-safe issue in practice because it's not a primitive.The underlined part is incorrect. A primitive may have thread-safety issues (unless it's immutable), and an object may not have such issues, depending on a number of factors.
    The put, get methods, which will be invoked probably, are not thread-safe although the reference to map is.Yes. And even if the put/get methods were synchronized, the client code could see consistency issues in a concurrent scenario, as demonstrated above.
    Additional considerations:
    1) read/write of primitive types are not necessarily atomic: section [ §17.7 of the JLS|http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.7] explicitly states that writing a long or double value (2 32-bits words) may not be atomic, and may be subject to consistency issues in a concurrent scenario.
    2) The Java Memory Model explicitly allows non-synchronized operations on non-volatile fields to be implemented in a "thread-unsafe" way by the JVM. Leading way to a lot of unintuitive problems such as the "Double-Checked Locking idiom is broken". Don't make clever guess on code execution path unless you properly synchronize access to variables across threads.
    Edited by: jduprez on Mar 4, 2010 9:53 AM

  • Instantiating a nested class from JNI

    Im able to instantiate my public member class "Inner" as long as the constructor does not take any arguments. If it requires arguments in the constructor, I get a crash report. I need to be able to instantiate the object with supplied initial arguments. Is this a bug in the JVM? Any suggestions?
    /dan
    Crash report follows after code:
    class HelloWorld {
       public class Inner {
          private int myValue = 50;
          public Inner() {}
          public Inner(int myValue) {
             this.myValue = myValue;
          public Inner(int myValue, int there) {
             this.myValue = myValue;
    }C++ library:
       jclass inr_clz = env->FindClass("LHelloWorld$Inner;");
       if (inr_clz == NULL) {
          return -25;               // failed to find the class
    //   mid = env->GetMethodID(inr_clz, "<init>", "(LHelloWorld;)V");              // works
       mid = env->GetMethodID(inr_clz, "<init>", "(LHelloWorld;II)V");            // also works
       if (mid == NULL) {
          return -30;                    // failed to get method
       jint value = 400;
    //   inner = env->NewObject(inr_clz, mid);                           // works
       inner = env->NewObject(inr_clz, mid, value, value);             // crash here
       if (inner == NULL) {
          return -40;                     // out of memory error
       ...Crash message:
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # Internal Error (53484152454432554E54494D450E43505001A3), pid=2008, tid=2628
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
    # An error report file with more information is saved as hs_err_pid2008.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    #

    Im able to instantiate my public member class "Inner"
    as long as the constructor does not take any
    arguments. If it requires arguments in the
    constructor, I get a crash report. I need to be able
    to instantiate the object with supplied initial
    arguments. Is this a bug in the JVM? Any
    suggestions?It's your code.
    Here's a working example:
    ==================
    public class NativeInnerTest {
         public static void main(String[] args) {
              new Outer().doNative();
    public class Outer {
         static {
              System.loadLibrary("outer");
         public class Inner {
              private int val;
              Inner (int val) {
                   this.val = val;
              public void foo() {
                   System.out.println("Value is: " + val);
         public native void doNative();
    }=====Native Code======================
    #include "Outer.h"
    JNIEXPORT void JNICALL Java_Outer_doNative (JNIEnv *env, jobject obj) {
         jclass clz = env->FindClass("Outer$Inner");
         if (clz == NULL) {
              printf("Failed to find class Outer$Inner");
              return;
         jmethodID mid = env->GetMethodID(clz,"<init>", "(LOuter;I)V");
         if (mid == NULL) {
              printf ("Failed to find Inner constructor\n");
              return;
         jint val = 42;
         jobject inner = env->NewObject(clz,mid,obj,val);
         if (inner == NULL) {
              printf ("Failed to construct Inner object\n");
              return;
         jmethodID fooID = env->GetMethodID(clz, "foo", "()V");
         if (fooID ==  NULL) {
              printf ("Failed to find method id for foo()\n");
              return;
         env->CallVoidMethod(inner, fooID);
    }================================
    The problem in your code is twofold. First, your type signature in the call to GetMethodID is incorrect. An inner class constructor taking a single integer argument should have a type signature like this:
    (LHelloWorld;I)V
    You can get the proper type signatures using the 'javap' tool. For my example, the output of javap looks like this:
    [jim@daisy tmp]$ /usr/java/jdk1.6.0/bin/javap -s -private Outer.Inner
    Compiled from "Outer.java"
    public class Outer$Inner extends java.lang.Object{
    private int val;
      Signature: I
    final Outer this$0;
      Signature: LOuter;
    Outer$Inner(Outer, int);
      Signature: (LOuter;I)V
    public void foo();
      Signature: ()V
    }Second, your call to NewObject does not have the proper parameter types. Here's your code:
    inner = env->NewObject(inr_clz, mid, value, value);The corresponding correct line from my example is:
    jobject inner = env->NewObject(clz,mid,obj,val);The constructor expects a 'HelloWorld' object and an integer as denoted in the correct
    type signature.
    You are passing in the integer 'val' twice when you should be doing something like this:
    inner = env->NewObject(inr_clz, mid, obj, value);where 'obj' is the jobject passed to you by the VM along with the JNIEnv pointer. This jobject represents the instance of the enclosing class which every non static nested class must have.
    Jim S.

  • Java returning incorrect values for width and height of a Tiff image

    I have some TIFF images (sorry, I cannot post them b/c of there confidential nature) that are returning the incorrect values for the width and height. I am using Image.getWidth(null) and have tried the relevant methods from BufferedImage. When I open the same files in external viewers (Irfanview, MS Office Document Imaging) they look fine and report the "correct" dimensions. When I re-save the files, my code works fine. Obviously, there is something wrong with the files, but why would the Java code fail and not the external viewers? Is there some way I can detect file problems?
    Here is the code, the relevant section is in the print() routine.
    * ImagePrinter.java
    * Created on Feb 27, 2008
    * Created by tso1207
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.print.PageFormat;
    import java.awt.print.PrinterException;
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.FileImageInputStream;
    import javax.imageio.stream.ImageInputStream;
    import com.shelter.io.FileTypeIdentifier;
    public class ImagePrinter extends FilePrintable
       private final ImageReader _reader;
       private final int _pageCount;
       private final boolean _isTiff;
       //for speed we will hold current page info in memory
       private Image _image = null;
       private int _imgWidth = 0;
       private int _imgHeight = 0;
       private int _currentPage = -1;
       public ImagePrinter(File imageFile) throws IOException
          super(imageFile);
          ImageInputStream fis = new FileImageInputStream(getFile());
          Iterator readerIter = ImageIO.getImageReaders(fis);
          ImageReader reader = null;
          while (readerIter.hasNext())
             reader = (ImageReader) readerIter.next();
          reader.setInput(fis);
          _reader = reader;
          int pageCount = 1;
          String mimeType = FileTypeIdentifier.getMimeType(imageFile, true);
          if (mimeType.equalsIgnoreCase("image/tiff"))
             _isTiff = true;
             pageCount = reader.getNumImages(true);
          else
             _isTiff = false;
          _pageCount = pageCount;
       public int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageIndex)
          throws java.awt.print.PrinterException
          int drawX = 0, drawY = 0;
          double scaleRatio = 1;
          if (getCurrentPage() != (pageIndex - getPageOffset()))
             try
                setCurrentPage(pageIndex - getPageOffset());
                setImage(_reader.read(getCurrentPage()));
                setImgWidth(getImage().getWidth(null));
                setImgHeight(getImage().getHeight(null));
             catch (IndexOutOfBoundsException e)
                return NO_SUCH_PAGE;
             catch (IOException e)
                throw new PrinterException(e.getLocalizedMessage());
             if (!_isTiff && getImgWidth() > getImgHeight())
                pf.setOrientation(PageFormat.LANDSCAPE);
             else
                pf.setOrientation(PageFormat.PORTRAIT);
          Graphics2D g2 = (Graphics2D) g;
          g2.translate(pf.getImageableX(), pf.getImageableY());
          g2.setClip(0, 0, (int) pf.getImageableWidth(), (int) pf.getImageableHeight());
          scaleRatio =
             (double) ((getImgWidth() > getImgHeight())
                ? (pf.getImageableWidth() / getImgWidth())
                : (pf.getImageableHeight() / getImgHeight()));
          //check the scale ratio to make sure that we will not write something off the page
          if ((getImgWidth() * scaleRatio) > pf.getImageableWidth())
             scaleRatio = (pf.getImageableWidth() / getImgWidth());
          else if ((getImgHeight() * scaleRatio) > pf.getImageableHeight())
             scaleRatio = (pf.getImageableHeight() / getImgHeight());
          int drawWidth = getImgWidth();
          int drawHeight = getImgHeight();
          //center image
          if (scaleRatio < 1)
             drawX = (int) ((pf.getImageableWidth() - (getImgWidth() * scaleRatio)) / 2);
             drawY = (int) ((pf.getImageableHeight() - (getImgHeight() * scaleRatio)) / 2);
             drawWidth = (int) (getImgWidth() * scaleRatio);
             drawHeight = (int) (getImgHeight() * scaleRatio);
          else
             drawX = (int) (pf.getImageableWidth() - getImgWidth()) / 2;
             drawY = (int) (pf.getImageableHeight() - getImgHeight()) / 2;
          g2.drawImage(getImage(), drawX, drawY, drawWidth, drawHeight, null);
          g2.dispose();
          return PAGE_EXISTS;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since version XXX
        * @return
       public int getPageCount()
          return _pageCount;
       public void destroy()
          setImage(null);
          try
             _reader.reset();
             _reader.dispose();
          catch (Exception e)
          System.gc();
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public Image getImage()
          return _image;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getImgHeight()
          return _imgHeight;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getImgWidth()
          return _imgWidth;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param image
       public void setImage(Image image)
          _image = image;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setImgHeight(int i)
          _imgHeight = i;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setImgWidth(int i)
          _imgWidth = i;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getCurrentPage()
          return _currentPage;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setCurrentPage(int i)
          _currentPage = i;
    }Edited by: jloyd01 on Jul 3, 2008 8:26 AM

    Figured it out. The files have a different vertical and horizontal resolutions. In this case the horizontal resolution is 200 DPI and the vertical is 100 DPI. The imgage width and height values are based on those resolution values. I wrote a section of code to take care of the problem (at least for TIFF 6.0)
       private void setPageSize(int pageNum) throws IOException
          IIOMetadata imageMetadata = _reader.getImageMetadata(pageNum);
          //Get the IFD (Image File Directory) which is the root of all the tags
          //for this image. From here we can get all the tags in the image.
          TIFFDirectory ifd = TIFFDirectory.createFromMetadata(imageMetadata);
          double xPixles = ifd.getTIFFField(256).getAsDouble(0);
          double yPixles = ifd.getTIFFField(257).getAsDouble(0);
          double xRes = ifd.getTIFFField(282).getAsDouble(0);
          double yres = ifd.getTIFFField(283).getAsDouble(0);
          int resUnits = ifd.getTIFFField(296).getAsInt(0);
          double imageWidth = xPixles / xRes;
          double imageHeight = yPixles / yres;
          //if units are in CM convert ot inches
          if (resUnits == 3)
             imageWidth = imageWidth * 0.3937;
             imageHeight = imageHeight * 0.3937;
          //convert to pixles in 72 DPI
          imageWidth = imageWidth * 72;
          imageHeight = imageHeight * 72;
          setImgWidth((int) Math.round(imageWidth));
          setImgHeight((int) Math.round(imageHeight));
          setImgAspectRatio(imageWidth / imageHeight);
       }

  • Flex RPC mapping Java nested classes to ActionScript classes

    We are calling a Java method in our project using
    RemoteObject the value returned by the java method is a ArrayList
    containing instances of a class say ParentClass with some nested
    classes.
    The structure of ParentClass(Java) is something like this
    class ParentClass {
    //some primitives
    private ChildClassA childAInstance;
    private ChildClassB childBInstance;
    //getters setters
    We have created similar class structure on the ActionScript
    side, the ActionScript classes(ParentClass,ChildClassA
    ,ChildClassB) have been properly annotated with the [RemoteClass]
    metadata tag,
    The problem is that though i'm getting the primitive data
    members of the ParentClass through RPC in my corresponding AS
    ParentClass class i'm getting an runtime exception trying to access
    ChildClassA,ChildClassB members.
    Am i missing something, exactly the same scenario is
    mentioned in this article
    http://www.adobe.com/devnet/flex/articles/complex_data.html
    But the Object.registerClass method mentioned in the tutorial
    is giving me compilation error, the sample code attached with the
    article is corrupt zip too.
    Please help me out on this

    JAXB will create classes from an XML schema, SAX is a parser library and JAXP is a library of XML a bunch of XML tools.
    I don't care for JAXB too much. I would skip it and go right to the JAX-RPC spec (WebServices).

  • Nested Classes in Labview 8.2

    hello everyone,
    I am a 'measurement studio' convert to labview, so I have been getting my head around the 'object oriented programming' features of labview 8.2. There seems to be many things lacking in this implementation, like Java/C# style interfaces, and abstract classes.
    Also I haven't found a way to create a nested class (so a class within a class). Is this possible in Labview 8.2 or 8.5?
    Thanks,
    paul

    I just stumbled across this post looking for other information......
    Is it true that nested classes are not supported?
    I just tried this out and it seemed to work for me.  Can we add a class as a data member of another class?  I think I recall this even being propagated in an article, but I can't remember which.
    I think it was about an object referencing itself in it's own data field to create a recursive object call.....
    Can someone please confirm that nested classes are supported and working?  Which caveats need to be observed?  I'm just starting working on something which kind of relies on the ability to nest classes, so I'm quite interested as to whether it's feasible or not.
    I'm using LV 8.2.1.
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • Nested Classes and Static Methods

    I was perusing the Java Tutorials on Nested Classes and I came across this...
    [http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html|http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html]
    I was reading the documentation and I read a slightly confusing statement. I was hoping some further discussion could clarify the matter. The documentation on "Nested Classes" says (I highlighted the two statements, in bold, I am having trouble piecing together.)
    Static Nested Classes
    As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ? it can use them only through an object reference.
    Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?

    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
        int i;
        static class Bar {
            int j = i; // WRONG! Bar class is static context
    }~

  • Nested classes and separate files in Javadoc...

    Hello. I am writing an application, and it has several .java files, and some of the classes contained therein contain nested classes, for example
    ClassOne.java
    class ClassOne
    // stuff
       class innerClassOne
          //more stuff
    }ClassTwo.java
    class ClassTwo
    // stuff
       class innerClassTwo
          //more stuff
    }What I want to do is generate documentation like the online java documentation for my app, that is, documentation that will contain ALL the classes and nested classes involved, and link everything that comes in java already to the sun online java docs.
    I've figured out the -link command for javadoc, and I can make that work, but I've run into some other snags.
    1.) Javadoc isn't finding or documenting my nested classes, despite them being marked up. Google does not wish to help.
    2.) Some classes reference other classes of mine that aren't conatined in the same .java file, but do exist in their own .java files in the dame local directory. Javadoc does not like this, and gives errors.
    3.) Running javadoc on one file at a time overwrites the old file's documentation, thus I cannot seem to get an index.html javadoc file that links to all my classes, nor can I get the classes to link to each other.
    What do I need to do to fix these?

    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
        int i;
        static class Bar {
            int j = i; // WRONG! Bar class is static context
    }~

  • JDWP reference implementation does not return anonymous nested classes?

    Using
    $ java -version
    java version "1.6.0_22"
    Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
    Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
    it appears that when I connect with JDWP and issue a NestedTypes command, the result does not include anonymous nested types. The only references to this that I could find is a comment in a svn commit at apache (http://mail-archives.apache.org/mod_mbox/harmony-commits/200611.mbox/%[email protected]%3E)
    Is this intentional and desired? Is there a way to get all of the nested types, including the anonymous ones? I could do ClassesBySignature with "package.ClassName$*" as the signature and filter out doubly nested classes, but that seems overly complicated.

    exept, you can NOT have an implementation of an
    abstract class (which foundPlugin) is without an
    implementation of all it's subclasses (such as
    argsObject) You're mistaken in a couple of ways here.
    First, a nested class is not the same as a subclass.
    Second, a concrete class must have implementations for all its methods, but it can still have an abstract nested class.
    Third, you can have an instance of a concrete class that has abstract subclasses. Object is concrete and has many concrete subclasses. Classes don't know anything about their subclasses.
    This compiles.
    public abstract class AbOut {
      public abstract class AbIn {  public abstract void bar(); }
    public class ConcOut extends AbOut {
      public abstract class AbIn2 { public abstract void foo();}
    foundPlugin MUST have an implementation
    of argsObject, according to the rules of java,And you think this because...?
    You read it in the JLS? Citation please.
    You tried to compile and it failed? My sample above demonstrates the countereample. If I'm misunderstanding what you're talking about, please post an example
    Or maybe you just thought it had to be that way because that seemed the most intuitive and when it wasn't, rather than trying to understand or adjust your thinking, you figured it would be more fun to throw a hissy fit and call Java "stupid"?

  • Questions concerning Nested Classes

    Hi!
    Just read some articles about nested classes (include the ones from the Java Tutorial and the Effective Java chapter), and while most of it is perfectly clear, three questions remain:
    1.) When I declare a member class, how should I declare the access specifiers (private, protected etc.) for the member class's attributes and methods? If I declare a member class as private, anything but private for the attributes and methods wouldn't make sense, would it?
    2.) The Java Tutorial says:
    Also, because an inner class is associated with an instance, it cannot define any static members itself.While this is true for static methods, it seems to be possible to declare static variables inside inner classes. This is confusing me... does it actually make sense to declare static variables inside inner classes (or member classes in general)? Or should the be placed in the declaring class?
    3.) Another confusing quote from the Java Tutorial:
    Static nested classes do not have access to other members of the enclosing class.This is true for instance variables and methods but not for static variables, which are also members of the enclosing class, aren't they?
    Thanks in advance,
    OIiver

    Trollhorn wrote:
    Hi!
    Just read some articles about nested classes (include the ones from the Java Tutorial and the Effective Java chapter), and while most of it is perfectly clear, three questions remain:
    1.) When I declare a member class, how should I declare the access specifiers (private, protected etc.) for the member class's attributes and methods? If I declare a member class as private, anything but private for the attributes and methods wouldn't make sense, would it?
        private static class MyInner implements Runnable
            @Override public void run() // Must be public!
    2.) The Java Tutorial says:
    Also, because an inner class is associated with an instance, it cannot define any static members itself.While this is true for static methods, it seems to be possible to declare static variables inside inner classes. This is confusing me... does it actually make sense to declare static variables inside inner classes (or member classes in general)? Or should the be placed in the declaring class?Wrong. It can define static final member variables and I see no reason to move them to the outer class, if they are used only by the inner class.
    3.) Another confusing quote from the Java Tutorial:
    Static nested classes do not have access to other members of the enclosing class.This is true for instance variables and methods but not for static variables, which are also members of the enclosing class, aren't they?I agree with you here.
    Edited by: baftos on Jun 6, 2009 9:18 AM

  • Compiling Nested Classes and Interfaces

    I am looking for documentation about compiling nested classes and interfaces. I have found something in the JVM Specification, but there does not explain how a nested class is compiled and what is included in the top level class to mark a "place holder" to the nested class. The JVM Specification in this topic cite the web page http://java.sun.com/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc.html that does not exists any more.
    My root problem is that: I am compiling a class with a private nested class, but in the class file generated TopLevelClass$NestedClass.class the class does not have the private modifier. So I am not understanding why the "private" modifier was removed during compilation.
    I performed the same test with a protected nested class and the result was the nested class with the public modifier. So I am not understanding why the "protected" modifier was changed to "public".
    Thanks in advance,
    Mardoqueu.

    This should not be happening. What compiler are you using? If it's a reasonably recent Sun compiler, could you post a minimal example?

  • How to ensure multiple nested classes static readonly initialization orders

    Hello,
    I am emulating the Java Enumeration in a first class class, with static readonly field initialization.
    In an effort to further categorize some instances, I embed them in nested classes. Something like this.
    class A : Enumeration
    public static class CatB
    public static readonly A FirstInstance = new B();
    public static readonly A SecondInstance = new B();
    public static class CatC
    public static readonly A ThirdInstance = new C();
    public static readonly A FourthInstance = new C();
    class B : A
    class C : A
    So far so good.
    One strain of Enumeration has built-in Ordinals, so I initialize them in the static ctor, or I make an effort to.
    static A()
    var values = GetValues().ToList();
    var ordinal = 0;
    values.ForEach(v => v.Ordinal = ++ordinal);
    Also, in places, so far so good.
    However, in a main method, I am referencing one of the enumerated instances, so calls to my GetValues() is returning nulls for that nested class. The other nested class instances are just fine, they return just fine.
    I could post more, but I think this illustrates the idea.
    I am suspicious that a strange static initialization order is jumbled up, as evidenced by nested static ctor debug statements I put in. I get one print and not the other.
    When I switch up which instance I reference in my main, I get the opposite behavior, more or less confirming my suspicions.
    So... Question is, what's the best way to potentially work around this issue? Hopefully without abandoning the Enumeration concern altogether, but that thought is a possibility as well. Or at least do so differently.
    Thank you...

    It is probably necessary to show GetValues() at least. I am getting the correct nested types, so that much we can at least assume.
    protected static IEnumerable<TDerived> GetValues()
    var declaringTypes = GetDeclaringTypes(typeof (TDerived)).ToArray();
    foreach (var declaringType in declaringTypes.Reverse())
    var fis = declaringType.GetFields(PublicStaticDeclaredOnly);
    var values = fis.Select(fi => fi.GetValue(null)).ToArray();
    foreach (var value in values.OfType<TDerived>())
    yield return value;
    Okay, here a bit of explanation.
    Enumeration is declared generically, with TDerived as the derived type. In this case, A.
    GetDeclaringTypes is operating okay. I get types for A, B, and C.
    The fis to values is breaking down, however. When I reference any of the CatB's, I get nulls for those instances. Conversely, same for CatC's when I reference any of those.

Maybe you are looking for

  • BP created in "Z" role in CRM

    Hello Experts We are maintaining Zroles such as ZSold-to party (ZCRM00) , ZShip-to party (ZCRM02) etc in customising. We have created BP with the above Z roles. I have also maintain relationship for these BPs as "Has contact person" Now when i login

  • Master Detail with Search

    Hi All, I have created a Master (Form with Navigation buttons) - Detail (table) with search region. Intially both regions show no data as expected. When I search for an entry in Master region - It shows the data in Master but not in Details region. W

  • Workflow does not work from Script Menu or as Application

    Hi, I create a really simple script to adjust podcast volume... 1. Get Specified iTunes Items (Recently added podcast – my smart folders of recently downloaded items) 2. Filter Songs in iTunes (Volume Adjustment is 0: so the workflow will not touch p

  • BAPI for J1IEX and MIRO

    Hi Experts, Is there any BAPI for J1IEX (Excise capturing) and MIRO posting. Regards, Hanuman.

  • Oracle Web Service Manager Login failed

    Hi , I had installed advance version of SOA 10.1.3.1 on windows xp. I abel to login to all component other than web service manager.I am using the oc4jadmin user id and its password to login.Please let me know what i have to do to fix it. Regards, Pa