Unreachable statement error in Java

Java Unreachable statement is an error according to the Java Language Spec . This error means that the control flow of your program can't get to that statement, but you assume that they would be. The compiler analyzes the flow, and reports these statements to you as error messages. It is a reliable indicators of logical error in your program. These statements might be unreachable mostly because of the following reasons:
- Return statement
- Infinite loop
Return statement
public bool myMessage()
{
return true;
/* The implementation goes here */
}
In the above example, the return function will terminate your method, meaning no line of code past it will be executed . If you want your print to go through, you should move it above the return statement. If you keep any statements after the return statement those statements are unreachable statements by the controller. By using return statement we are telling control should go back to its caller explicitly .
Infinite loop
for(;;){
break;
System.out.print("inside infinite loop");
}

Related Topics
- Reached end of file while parsing
- Int Cannot Be Dereferenced Error - Java
- How to fix java.lang.classcastexception
- How to fix java.util.NoSuchElementException
- How to fix "illegal start of expression" error
- How to resolve java.net.SocketException: Connection reset
- Non-static variable cannot be referenced from a static context
- Error: Could not find or load main class in Java
- How to Handle OutOfMemoryError in Java
- How to resolve java.net.SocketTimeoutException
- How to handle the ArithmeticException in Java?