Results 1 to 5 of 5
  1. #1
    Lowest0ne is offline Member
    Join Date
    Apr 2012
    Posts
    21
    Rep Power
    0

    Default Amount of .class files created

    I have a linked list:
    Java Code:
    public class SortedLinkedList<E extends Comparable<E>>
    {
      private class Node<E>
      {
        Node(E d) {data = d; next = null; prev = null;}
      }
      protected class Iterator<E>{}
    }
    Which when compiled, I get three .class files:

    SortedLinkedList.class
    SortedLinkedList&Node.class
    SortedLinkedList&Iterator.class

    Now I am working on member access (friend/protected/private), and I've changed the Node's constructor to private:
    Java Code:
    public class SortedLinkedList<E extends Comparable<E>>
    {
      private class Node<E>
      {
        private Node(E d) {data = d; next = null; prev = null;}
      }
      protected class Iterator<E>{  }
    }
    A little odd to me that the program still compiles (1.7.0), but I am given a fourth .class:

    SortedLinkedList$1.class

    Why is this? Thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Amount of .class files created

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Amount of .class files created

    Don't see why the program shouldn't compile.
    There's nothing there that would prevent it.

    The extra class is a bit of a mystery, though.
    Please do not ask for code as refusal often offends.

  4. #4
    Lowest0ne is offline Member
    Join Date
    Apr 2012
    Posts
    21
    Rep Power
    0

    Default Re: Amount of .class files created

    ~What an honor to be moved out of beginners :). I had my head shrunk later that day, no worries. ~

    There's nothing there that would prevent it.
    I just figured the SortedLinkedList wouldn't have access to the Node's constructor.

    Just did a little testing on an updated list:
    Java Code:
    // Needed code only
    public class SortedLinkedList<E extends Comparable<E>, F>
    {
      private class Node<E extends Comparable<E>, F>
      {
        private Node(E k, F d){}  
        private Node(Node<E, F> other){}
      }
    }
    Two constructors, maybe I would get a "SortedLinkedList&2.class" or something like that? Nope, still only &1.

    I did delete the &1, and the program still runs correctly (the way I've implemented it, at least)

    As a side, I just did this (removed the typed parameters from Node):

    Java Code:
    public class SortedLinkedList<E extends Comparable<E>, F>
    {
      private class Node
      {
        E key;
        F data;
      }
    }
    Seems to be working fine?
    Last edited by Lowest0ne; 12-03-2012 at 03:50 PM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Amount of .class files created

    Quote Originally Posted by Lowest0ne View Post
    I just figured the SortedLinkedList wouldn't have access to the Node's constructor.
    The 'private' is to do with stuff accessing from outside of the outer class, not child classes, so in this case another class could not create a Node.
    But Node is a part of a SortedLinkedList, as much as any member variable or method, so SortedLinkedList can execute private methods/constructors and access private attributes.
    To be honest, since the Node class is 'private' itself, the declaration of the constructors as 'private' will have no practical effect. Nothing outside of SortedLinkedList could access it anyway.

    Quote Originally Posted by Lowest0ne View Post
    Just did a little testing on an updated list:
    Java Code:
    // Needed code only
    public class SortedLinkedList<E extends Comparable<E>, F>
    {
      private class Node<E extends Comparable<E>, F>
      {
        private Node(E k, F d){}  
        private Node(Node<E, F> other){}
      }
    }
    Two constructors, maybe I would get a "SortedLinkedList&2.class" or something like that? Nope, still only &1.

    I did delete the &1, and the program still runs correctly (the way I've implemented it, at least)
    I expect something would turn up, though it is possible it's a compiler curiosity.

    Quote Originally Posted by Lowest0ne View Post
    As a side, I just did this (removed the typed parameters from Node):

    Java Code:
    public class SortedLinkedList<E extends Comparable<E>, F>
    {
      private class Node
      {
        E key;
        F data;
      }
    }
    Seems to be working fine?
    Node is part of SortedLinkedList, so it has "access" to the same things, including what generics are being applied.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. accessing xml files created during runtime
    By mniz13 in forum Advanced Java
    Replies: 7
    Last Post: 07-14-2011, 10:07 PM
  2. load jar files created with tbc
    By Inbarb in forum Eclipse
    Replies: 0
    Last Post: 02-27-2011, 07:14 AM
  3. can you tell how transfer a List eg. created as...between files jsp/java
    By lse123 in forum JavaServer Pages (JSP) and JSTL
    Replies: 21
    Last Post: 02-10-2010, 08:52 AM
  4. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM
  5. iteration on huge amount of files in a folder
    By tshaked in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 07:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •