Deep nested static class

Discussion in 'Java' started by Koos Pol, Nov 8, 2004.

  1. Koos Pol

    Koos Pol Guest

    Hello,

    I'm trying to create a method "bar" with very limited
    scope/visibilty, only existing within the scope of "foo".
    The following code results in "Illegal start of expression"


    class test {

    public static void main(String args[]) {
    }

    private static void foo() {
    private static bar() {
    }
    }
    }


    Apparently deep nesting of methods seems impossible. Is this true?

    For the curious, bar() contains calculation logic only valid
    within the context of foo().

    Thanks,
    Koos

    --
    KP
    43rd Law of Computing: "Anything that can go wr
    fortune: Segmentation violation -- Core dumped
     
    Koos Pol, Nov 8, 2004
    #1
    1. Advertising

  2. Koos Pol wrote:
    > Apparently deep nesting of methods seems impossible. Is this true?


    Nesting of methods is impossible, period.
     
    Michael Borgwardt, Nov 8, 2004
    #2
    1. Advertising

  3. Koos Pol

    Andy Flowers Guest

    If bar() is only valid in the context of foo how about using classes ?

    i.e.

    class HandleFoo
    {
    private void bar() {...}

    public void foo()
    {
    init class level PRIVATE variables
    call bar....
    }
    }

    or even nested classes ??
    http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#246214

    "Koos Pol" <> wrote in message
    news:newscache$sc2v6i$hpe$...
    > Hello,
    >
    > I'm trying to create a method "bar" with very limited
    > scope/visibilty, only existing within the scope of "foo".
    > The following code results in "Illegal start of expression"
    >
    >
    > class test {
    >
    > public static void main(String args[]) {
    > }
    >
    > private static void foo() {
    > private static bar() {
    > }
    > }
    > }
    >
    >
    > Apparently deep nesting of methods seems impossible. Is this true?
    >
    > For the curious, bar() contains calculation logic only valid
    > within the context of foo().
    >
    > Thanks,
    > Koos
    >
    > --
    > KP
    > 43rd Law of Computing: "Anything that can go wr
    > fortune: Segmentation violation -- Core dumped
     
    Andy Flowers, Nov 8, 2004
    #3
  4. Koos Pol

    Koos Pol Guest

    Michael Borgwardt wrote (Monday 08 November 2004 13:59):

    >> Apparently deep nesting of methods seems impossible. Is this
    >> true?

    >
    > Nesting of methods is impossible, period.


    Ok, that's settled then... :-(

    --
    KP
    43rd Law of Computing: "Anything that can go wr
    fortune: Segmentation violation -- Core dumped
     
    Koos Pol, Nov 8, 2004
    #4
  5. Koos Pol

    Koos Pol Guest

    Andy Flowers wrote (Monday 08 November 2004 14:26):

    > If bar() is only valid in the context of foo how about using
    > classes ?
    >
    > i.e.
    >
    > class HandleFoo
    > {
    > private void bar() {...}
    >
    > public void foo()
    > {
    > init class level PRIVATE variables
    > call bar....
    > }
    > }



    I've considered that but I hate it to see bar() taken out of the
    foo() context. bar() doesn't have a need to exist outside foo().

    > or even nested classes ??


    http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#246214

    Thanks for the pointer!

    Koos
    --
    KP
    43rd Law of Computing: "Anything that can go wr
    fortune: Segmentation violation -- Core dumped
     
    Koos Pol, Nov 8, 2004
    #5
  6. Koos Pol wrote:

    > Andy Flowers wrote (Monday 08 November 2004 14:26):
    >
    >
    >>If bar() is only valid in the context of foo how about using
    >>classes ?


    > I've considered that but I hate it to see bar() taken out of the
    > foo() context. bar() doesn't have a need to exist outside foo().


    Then you are characterizing the foo() problem wrongly. In Java, classes
    are the principal unit of code encapsulation, and objects are the
    principal unit of data encapsulation. You are focusing on a desired
    solution and trying to fit it to Java, instead of seeking the best Java
    idiom for accomplishing your task.


    John Bollinger
     
    John C. Bollinger, Nov 8, 2004
    #6
  7. Koos Pol

    Koos Pol Guest

    John C. Bollinger wrote (Monday 08 November 2004 17:43):

    > You are focusing on a
    > desired solution and trying to fit it to Java, instead of
    > seeking the best Java idiom for accomplishing your task.


    Spot on :)
    I have a big mind shift to make (Perl) so it'll take a while
    before it feels naturally to me.

    --
    KP
    43rd Law of Computing: "Anything that can go wr
    fortune: Segmentation violation -- Core dumped
     
    Koos Pol, Nov 9, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,788
    Thomas Weidenfeller
    Oct 12, 2005
  2. Alfonso Morra

    performing a "deep copy" on a nested structure

    Alfonso Morra, Sep 30, 2005, in forum: C Programming
    Replies:
    1
    Views:
    275
    Flash Gordon
    Sep 30, 2005
  3. request@no_spam.com
    Replies:
    5
    Views:
    431
  4. Robin
    Replies:
    0
    Views:
    420
    Robin
    Jun 6, 2007
  5. Sky
    Replies:
    4
    Views:
    183
    Sky Sigal
    Jul 19, 2004
Loading...

Share This Page