Results 1 to 5 of 5
Thread: Amount of .class files created
- 12-01-2012, 05:36 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
Amount of .class files created
I have a linked list:
Which when compiled, I get three .class files: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>{} }
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:
A little odd to me that the program still compiles (1.7.0), but I am given a fourth .class: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>{ } }
SortedLinkedList$1.class
Why is this? Thanks.
- 12-01-2012, 05:52 PM #2
Re: Amount of .class files created
Moved from New to Java
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-03-2012, 10:50 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 12-03-2012, 03:44 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
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. ~
I just figured the SortedLinkedList wouldn't have access to the Node's constructor.There's nothing there that would prevent it.
Just did a little testing on an updated list:
Two constructors, maybe I would get a "SortedLinkedList&2.class" or something like that? Nope, still only &1.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){} } }
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):
Seems to be working fine?Java Code:public class SortedLinkedList<E extends Comparable<E>, F> { private class Node { E key; F data; } }Last edited by Lowest0ne; 12-03-2012 at 03:50 PM.
- 12-03-2012, 04:02 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Amount of .class files created
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.
I expect something would turn up, though it is possible it's a compiler curiosity.
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
-
accessing xml files created during runtime
By mniz13 in forum Advanced JavaReplies: 7Last Post: 07-14-2011, 10:07 PM -
load jar files created with tbc
By Inbarb in forum EclipseReplies: 0Last Post: 02-27-2011, 07:14 AM -
can you tell how transfer a List eg. created as...between files jsp/java
By lse123 in forum JavaServer Pages (JSP) and JSTLReplies: 21Last Post: 02-10-2010, 08:52 AM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
iteration on huge amount of files in a folder
By tshaked in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks