Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6708543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:46:21+00:00 2026-05-26T07:46:21+00:00

void run() { … if (done) return cancel(); … } where cancel() return void

  • 0
void run() {
    ...
    if (done) return cancel();
    ...
}

where cancel() return void. This won’t compile… and I can almost understand why. But if I want to return a void from a void, why not? Instead, I end up writing something like this:

if (done) {
    cancel();
    return;
}

I’m not looking for code style suggestions, I want to know why Java expressly prohibits this type of void return. Any info is appreciated, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:46:21+00:00Added an answer on May 26, 2026 at 7:46 am

    A return statement with an expression returns the value of that expression. The type of cancel() is a void expression – it doesn’t have a value.

    Logically you want to execute cancel(), and then return – so that’s what you have to say. The two actions (calling cancel() and then returning) are logically distinct.

    Now Java could have a sort of “unit” type instead of void – but that would affect rather more than just return values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the Code below: string GetName(Type type) { return ((type)this.obj).Name; } void Run() {
//MainClass.m @interface InnerClass : NSObject{ } @end @implementation InnerClass -(void)run{ while(isActive){//want to access this
Say I've got something like this public void run(){ Thread behaviourThread = new Thread(abstractBehaviours[i]);
void (int a[]) { a[5] = 3; // this is wrong? } Can I
I have the following: class DThread { virtual void run()=0; _beginthreadex(NULL,0,tfunc,this,0,&m_UIThreadID); // class itself
snippet from The Server code : public void run() { try { // Create
I have this code: try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try
I have this simple code: public void Run() { var invokerThread = new Thread(new
I have the following : Runnable done = new Runnable() { public void run()
I create a new thread like this: Runnable r=new Runnable() { public void run()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.