Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Wy no error is reported for this bad cast ?
Wy no error is reported for this bad cast ? [message #251593] Thu, 21 February 2008 12:36 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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();
> }
> }
Re: Wy no error is reported for this bad cast ? [message #251602 is a reply to message #251598] Thu, 21 February 2008 12:57 Go to previous message
Eclipse UserFriend
Originally posted by: none.domain.invalid

Ed Merks a écrit :
> The value might be an instance of
>
> public class IB extends B implements I
> {
> }

Thanks! I added a final to "B" class, and there was errors :)
Previous Topic:Need a recap on JSR-045 !
Next Topic:Thank you so much for the Javadoc hover with hyperlinks !!!
Goto Forum:
  


Current Time: Tue Sep 17 14:25:18 GMT 2024

Powered by FUDForum. Page generated in 0.03555 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top