wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes I was expecting Unreachable statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "I was expecting Unreachable statement" Watch "I was expecting Unreachable statement" New topic
Author

I was expecting Unreachable statement

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 222



Oracle Java Programmer , Oracle SQL Expert
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

The compiler doesn't examine the contents of a method you're calling to decide whether it will ever return or not. As far as the compiler is concerned you call go(), and then print something out. To get an "unreachable statement" error you need it to be clear just by looking at static details of the method in question that it will never get there.
Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 222

Thank You it was fast
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Mahtab Alam wrote:Thank You it was fast

You're welcome!
Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 222



class A<T>
{

public <K> A<? super K> get(){return new A();}

}

It compiles fine although with one warning
I thought it will not compile .
How can a return type of A be assigned to A<? super K> .
So only possible assignment for A<? super K> should be

A<? super K> K and super type of K.And since K extends Object.
How is it Ok
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I was expecting Unreachable statement
 
Similar Threads
Exception handling problem
Unreachable statements
Assertions
What is this() method
Thinking in Java problem