access to anonymous inner class instance from another package

L

Lew

Wojtek said:
Peter Duniho wrote :
Robert Dodier wrote:
Anonymous classes avoid clutter, why not
anonymous methods as well.

Because of the implementation of the JVM and the strong static typing
nature of Java makes first-class methods tricky to implement.

The first point (implementation of JVM) might be valid. The second
(strong static typing) certainly is not. Other strongly typed
languages have closures, without any real tricky aspects at all.
[...]
The developers of Java decided that interface-based programming was
much cleaner than function pointer-based programming, and from a
maintainability perspective, I think most people would agree with them.

"Most" from what sample set? The one thing I find most awkward about
Java is its lack of a proper function pointer type and closures. One
of the things I love most about C# is those features. I dare say that
looking at a broader set of people, you'd find that many, if not most,
would agree that one of the things holding Java back the most is its
refusal to include any functional-style paradigms.

Hmmm, function pointers...

interface Foo
{
public void doSomething();
}

class One implements Foo
{
One()
{
}

public void doSomething()
{
// stuff to be done
}
}

class Two implements Foo
{
Two()
{
}

public void doSomething()
{
// stuff to be done
}
}

enum FooHolder
{
ONE(new One()),
TWO(new Two());

private Foo foo;

FooHolder(Foo fooIn)
{
foo = fooIn;
}

public Foo getFoo()
{
return foo;
}

better:
public void doSomething()
{
this.foo.doSomething();
}
}


...

FooHolder.ONE.getFoo().doSomething();

FooHolder.ONE.doSomething();
or

work(Foo.TWO);

public void work(FooHolder foo)
{
foo.getFoo().doSomething();

foo.doSomething();
}

Off the top of my head, but the syntax is basically sound.

This is what people are calling "too verbose" and has them clamoring for
first-class functions.

(The verbosity of the holder idiom doesn't count - it'd still be there with a
real closure.)

This is a religious argument, of course. I'm not out to convert anyone, just
express an opinion.
 
M

Mark Space

Wojtek wrote:
This is what people are calling "too verbose" and has them clamoring for
first-class functions.


I think what people are complaining about is the verbosity of anonymous
classes.

public static void someMethod() {
Foo foo = new Foo() {
@Override
public void doSomething() {
int two = 1+1;
}
};
}

rather than just
public static void someMethod() {
Foo foo = doSomething() { void -> 1+1 };
}

or something similar to that. This is more similar to what I see when
folks request "anonymous" functions. And probably some better way of
dealing with the parameters than inner classes provide (unfortunately
doSomething doesn't have any).
 
M

Mike Schilling

Robert said:
Well, this is Usenet, so feel free to jump to conclusions ...
everyone else does.

See, I went to the effort of being polite, and I got rudeness in reply. Go
**** yourself.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top