Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11020

Re: Inner class and interface question (I posted some really long code)

From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
Newsgroups comp.lang.java.programmer
Subject Re: Inner class and interface question (I posted some really long code)
References <e787d461-ab1a-417a-9c81-0caa4d1e7ac8@x34g2000prb.googlegroups.com>
Message-ID <IxzKq.47710$cN1.2696@newsfe12.iad> (permalink)
Date 2011-12-27 23:27 -0800

Show all headers | View raw


On 12/27/11 10:29 PM, Chad wrote:
> I'm want to put the getHead() method in the BagInterface. However, I
> can't do this because the compiler keeps saying it can't find 'class
> Node' in Location BagInterface<T>. I guess this is because Node is an
> inner class of my LinkedList class. Ideas how to fix this? Ideally I
> want to preserve the inner class. Below is the complete working code
> in question.
>
> public class Main {
>
>      public static void main(String[] args) {
>          BagInterface<Integer>  list = new LinkedList<Integer>();
>          list.add(new Integer(1));
>          list.add(new Integer(2));
>          list.add(new Integer(100));
>          list.add(new Integer(100));
>          list.add(new Integer(100));
>          list.add(new Integer(100));
>          list.add(new Integer(99));
>          list.add(new Integer(11));
>          list.printMe();
>          //System.out.println("The sum is " +
> list.sumMe(list.getHead()));
>
>      }//end main
> }
>
> interface BagInterface<T>  {
>      public void add(T newData);
>      public void printMe();
>      public Node getHead(); //<---Problem Line
>
> }
>
[snip]
Node is specific to LinkedList, and doesn't belong in Bag. As a matter 
of fact, "getHead()" doesn't make sense in Bag at all, and on top of 
that, exposing "Node" out of a collection class seems to me to be a very 
bad leaking of encapsulation

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Inner class and interface question (I posted some really long code) Chad <cdalten@gmail.com> - 2011-12-27 22:29 -0800
  Re: Inner class and interface question (I posted some really long code) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-12-27 23:27 -0800
  Re: Inner class and interface question (I posted some really long code) Patricia Shanahan <pats@acm.org> - 2011-12-28 09:53 -0800
  Re: Inner class and interface question (I posted some really long code) GGolf <invalid@invalid.com> - 2011-12-30 12:32 +0530
    Re: Inner class and interface question (I posted some really long code) Patricia Shanahan <pats@acm.org> - 2011-12-30 05:40 -0800
  Re: Inner class and interface question (I posted some really long code) Roedy Green <see_website@mindprod.com.invalid> - 2011-12-31 06:40 -0800

csiph-web