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


Groups > comp.lang.java.help > #1286

Re: Enum basics

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Enum basics
Date 2011-11-05 00:51 -0700
Organization http://groups.google.com
Message-ID <11919463.149.1320479510450.JavaMail.geo-discussion-forums@prgt10> (permalink)
References <3bo8b7dd306f6pj50v2jk3t9704n1c0cjp@4ax.com> <nospam-E313EF.20444304112011@news.aioe.org> <21054701.30.1320463633638.JavaMail.geo-discussion-forums@prog16> <nospam-FF2E16.02234105112011@news.aioe.org>

Show all headers | View raw


John B. Matthews wrote:
> Lew wrote:

...
>> Boom.  Second question answered.  No, an enum cannot access an 
>> enclosing class's instance members.  What's the big mystery?
> 
> D'oh, I misread the question, thinking of _static_ members of the 
> enclosing class; Roedy clearly said _instance_.

Yeah, I had to reread the post a couple of times to make sure I had the sense of it right way 'round.

As for my post upthread, the "you" there was the generalized "you, the reader", not you the poster.  I was writing a post, not an email, so what I said was not meant for anyone to take personally but in the spirit of an essay.

Just in case, you know.

As for the distinction between "nested" (i.e., static) and "inner" (instance) classes, I have been much more sensitive to the fine distinction after encountering the interesting edge case of an inner class that inherits from its containing class and accesses the latter's private members.


package eegee;
public class Outer
{
  private String foo()
  {
    return "Outer.foo() ";
  }

  protected String bar()
  {
    return "Outer.bar() ";
  }

  class Inner extends Outer
  {
    public String foo()
    {
      return "Inner.foo() ";
    }

    public String bar()
    {
      return "Inner.bar() ";
    }
  }

  public static void main(String [] args)
  {
    Outer encloser = new Outer();
    Inner inner = encloser.new Inner();
    Outer outer = inner;
    System.out.println("encloser: " + encloser.foo() + encloser.bar());
    System.out.println("   outer: " + outer.foo() + outer.bar());
    System.out.println("   inner: " + inner.foo() + inner.bar());
  }
}

Of course, @Override helps here.

-- 
Lew

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


Thread

Enum basics Roedy Green <see_website@mindprod.com.invalid> - 2011-11-04 15:11 -0700
  Re: Enum basics "John B. Matthews" <nospam@nospam.invalid> - 2011-11-04 20:44 -0400
    Re: Enum basics Lew <lewbloch@gmail.com> - 2011-11-04 20:27 -0700
      Re: Enum basics "John B. Matthews" <nospam@nospam.invalid> - 2011-11-05 02:23 -0400
        Re: Enum basics Lew <lewbloch@gmail.com> - 2011-11-05 00:51 -0700
      Re: Enum basics Roedy Green <see_website@mindprod.com.invalid> - 2011-11-05 04:12 -0700
        Re: Enum basics Lew <lewbloch@gmail.com> - 2011-11-05 09:15 -0700
          Re: Enum basics Patricia Shanahan <pats@acm.org> - 2011-11-05 14:06 -0700
            Re: Enum basics Lew <lewbloch@gmail.com> - 2011-11-05 15:54 -0700
            Re: Enum basics Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-05 20:43 -0300
            Re: Enum basics markspace <-@.> - 2011-11-05 19:55 -0700
            Re: Enum basics Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-11-05 22:10 -0500
  Re: Enum basics Roedy Green <see_website@mindprod.com.invalid> - 2011-11-05 04:18 -0700

csiph-web