Solved

Narrowing Conversion of Class type to Interface type

Posted on 2004-09-10
7
170 Views
Last Modified: 2010-03-31
how and why is the narrowing-reference-conversion "from any class type S to any interface type K, provided that S is not final and does not implement K" allowed or performed in java-language and jvm  ?
0
Comment
Question by:vxexpkuma2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12029638
Schoolwork?
0
 

Author Comment

by:vxexpkuma2
ID: 12030079
no. trying to understand the basics of java.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 12030287
OK, i'll take your word for it. The above proposition is incorrect, as the following demonstrates:

class X {
      interface K {}
      final class S implements K {}

      public X() {
            K k = new S();
      }
}
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 12031775
> provided that S is not final and does not implement K

S must implement K to be able to cast it to K
0
 
LVL 2

Expert Comment

by:SaMuEl
ID: 12032182
>> how and why is the narrowing-reference-conversion "from any class type S to any interface type K, provided that S is not final and does not implement K" allowed or performed in java-language and jvm  ?

Trick question, it's not.
As objects says, and CEHJ's code demonstartes, S must implement K for it to be allowed.
It makes no difference if S is final or not. Only if it were abstract.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question