harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick McGuire <rick...@gmail.com>
Subject Re: JVM Spec Interpretation Question
Date Tue, 17 Jan 2006 11:18:52 GMT
rohit hitnalikar wrote:
> Hello Gurus,
>   I am not able to understand the following bit from JVM spec v2.0
> which talks about permitted narrowing reference conversions:
>   *From any class type S to any interface type K, provided that S is not
> final and does not implement K. (An important special case is that
> there is a narrowing conversion from the class type Object to any interface
> type.)
Grrr, sorry about the mostly empty reply before...keystroke problems in 

Ok, here's a simple case:

public class Base {

public interface AnInterface {

public class SubBase extends Base implements AnInterface

Base a = new SubBase();

AnInterface b = (AnInterface)a;

At the point of the cast, the compiler is unable to determine if 
reference "a" is an object that implements AnInterface.  The base class 
Base does not, but a superclass might, so this narrowing must be allowed.

However, if Base was final, then it cannot have subclasses and thus this 
narrowing cannot succeed.

> *
>   Can somebody please let me know how to correctly interpret this?
>   In what cases, do we come across the need to use such a feature ? an
> example would be most helpful.
>   This bit is taken from the following links :
> http://java.sun.com/docs/books/vmspec/2nd-edition/html/Concepts.doc.html#32879
>   or here
> http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25379
> thanks in advance,
> Rohit

View raw message