3 Replies - 116 Views - Last Post: 18 July 2012 - 03:05 PM Rate Topic: -----

#1 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 196
  • View blog
  • Posts: 1,628
  • Joined: 13-March 10

SwingWorker question

Posted 17 July 2012 - 04:05 PM

Lets say we have the following worker:

SW<Void, Void>(){

Void doInB(){
....
...
return null;
}


My question: why does SwingWorker force us to return nulls if the doInB() method does not return anything. When we write our own functions in Java we can have void without return statements.
Why was SwingWorker designed in this fashion?
Is This A Good Question/Topic? 0
  • +

Replies To: SwingWorker question

#2 Ghlavac  Icon User is offline

  • D.I.C Addict

Reputation: 83
  • View blog
  • Posts: 505
  • Joined: 14-January 09

Re: SwingWorker question

Posted 17 July 2012 - 06:30 PM

Because SwingWorker specifies return types via generics and 'void' isn't a valid generic keyword.
Was This Post Helpful? 2
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9161
  • View blog
  • Posts: 33,981
  • Joined: 27-December 08

Re: SwingWorker question

Posted 17 July 2012 - 06:41 PM

There is actually a Void class to represent a void return type for this purpose.

http://docs.oracle.c.../lang/Void.html

Quote

Why was SwingWorker designed in this fashion?

It's not SwingWorker specifically. It goes with the territory of generics, and how methods work.
Was This Post Helpful? 1
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8066
  • View blog
  • Posts: 31,310
  • Joined: 06-March 08

Re: SwingWorker question

Posted 18 July 2012 - 03:05 PM

View Postmacosxnerd101, on 17 July 2012 - 09:41 PM, said:

There is actually a Void class to represent a void return type for this purpose.

http://docs.oracle.c.../lang/Void.html


Cute, I had to write my own once, never thought the API might contained one :)
:^:

This post has been edited by pbl: 18 July 2012 - 03:44 PM
Reason for edit:: quote tags

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1