Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Generics in return types

Thread view: 
kelvSYC - 13 Dec 2007 16:08 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.