Deep nested static class

K

Koos Pol

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
 
K

Koos Pol

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
 
J

John C. Bollinger

Koos said:
Andy Flowers wrote (Monday 08 November 2004 14:26):
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
(e-mail address removed)
 
K

Koos Pol

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top