One application of generics is probably in a return type, for example
public class Delegate<Ret> {
public Ret dothis() {
// ...
}
}
This of course implies that something is to be returned. Now, this
has probably been asked before, but what is a safe way to simulate a
void delegate? Would it be to do something like:
public class VoidDelegate extends Delegate<Void> {
public Void dothis() {
// ...
return null; // Void is non-instanced, so that's the only
thing we can return
}
}
RedGrittyBrick - 13 Dec 2007 16:54 GMT
> One application of generics is probably in a return type, for example
>
[quoted text clipped - 15 lines]
> }
> }
I came across this recently with SwingWorker. From memory, Eclipse
objected to every Void/void combo I tried except for
new SwingWorker<Void, Void>() {
protected Void doInBackground() {
...
return null;
}
protected void done() {
...
}
}
Note the use of small-v void and no return for done().
This seems odd to me but maybe someone can make sense of it?
kelvSYC - 13 Dec 2007 17:43 GMT
> Note the use of small-v void and no return for done().
> This seems odd to me but maybe someone can make sense of it?
That's because done() javax.swing.SwingWorker is not generic.