Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Narrowing Conversion of Class type to Interface type

Posted on 2004-09-10
7
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

610 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