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 8727341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:25:10+00:00 2026-06-13T08:25:10+00:00

Possible Duplicate: Compiler complains about missing return statement even though it is impossible to

  • 0

Possible Duplicate:
Compiler complains about “missing return statement” even though it is impossible to reach condition where return statement would be missing

The following method in Java compiles fine.

public String temp() {
    while(true) {
        if(true) {
            // Do something.
        }
    }
}

The method has an explicit return type which is java.lang.String with no return statement though it compiles fine. The following method however fails to compile.

public String tempNew() {
    if(true) {
        return "someString";
    }        
}

A compile-time error is issued indicating “missing return statement” even though the condition specified with the if statement is always true (it has a boolean constant that is never going to be changed neither by reflection). The method must be modified something like the following for its successful compilation.

public String tempNew() {
    if(true) {
        return "someString";
    } else {
        return "someString";
    }
}

or

public String tempNew() {
    if(true) {
        return "someString";
    }

    return "someString";
}

Regarding the first case with the while loop, the second case appears to be legal though it fails to compile.

Is there a reason in the second case beyond one of the compiler’s features.

  • 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-06-13T08:25:11+00:00Added an answer on June 13, 2026 at 8:25 am

    Because it is dead code. The dead code analysis is done in a separate pass to the method return analysis, which does some more in-depth analysis that looks inside branch conditions.

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

Sidebar

Related Questions

Possible Duplicate: Java - why no return type based method overloading? The compiler does
Possible Duplicate: Configuring the GCC compiler switches in Qt, QtCreator, and QMake I would
Possible Duplicate: How to code a compiler in C? How would I start writing
Possible Duplicate: Custom Compiler Warnings Duplicate: Custom Compiler Warnings I'm new to writing my
Possible Duplicate: C compiler bug (floating point arithmetic)? I've got two doubles which I
Possible Duplicate: Does the compiler continue evaluating an expression where all must be true
Possible Duplicate: JIT compiler vs offline compilers So until a few minutes ago I
Possible Duplicate: ant error JAVA_HOME does not point to SDK I'm getting the following
Possible Duplicate: Override the compiler attribute in an Ant javac task In Ant, how
Possible Duplicate: Learning to write a compiler I looked around trying to find out

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.