Wy no error is reported for this bad cast ? [message #251593] |
Thu, 21 February 2008 12:36 |
Eclipse User |
|
|
|
Originally posted by: none.domain.invalid
In the test case below, why the forced cast is OK ?
I'm using 3.4M5. Should i fill a bug or is it a "feature" ?
public class TestCast {
public interface I { }
public class B { }
public class Container {
Object get() { return null; }
}
public class SubContainer {
I get() { return null; }
}
void foo() {
Object[] objets = new Object[1];
// Type mistmath: Cannot convert from TestCast.I to TestCast.B
B b1 = ((SubContainer) objets[0]).get();
// forcing the cast is OK
B b2 = (B)((SubContainer) objets[0]).get();
}
}
|
|
|
Re: Wy no error is reported for this bad cast ? [message #251598 is a reply to message #251593] |
Thu, 21 February 2008 12:46 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
The value might be an instance of
public class IB extends B implements I
{
}
Name wrote:
> In the test case below, why the forced cast is OK ?
>
> I'm using 3.4M5. Should i fill a bug or is it a "feature" ?
>
> public class TestCast {
> public interface I { }
>
> public class B { }
>
> public class Container {
> Object get() { return null; }
> }
>
> public class SubContainer {
> I get() { return null; }
> }
>
> void foo() {
> Object[] objets = new Object[1];
>
> // Type mistmath: Cannot convert from TestCast.I to TestCast.B
> B b1 = ((SubContainer) objets[0]).get();
>
> // forcing the cast is OK
> B b2 = (B)((SubContainer) objets[0]).get();
> }
> }
|
|
|
|
Powered by
FUDForum. Page generated in 0.03734 seconds