![]() |
Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
Using an interface where you might expect to see a class is not only allowed, but generally good practice - so casting to an interface has to be allowed. As long as the object that is being cast is of a class which implements the interface, there is no problem - every method in the interface MUST be included in the object. If you try to cast an object which is of a class which does not implement the interface, you will get a ClassCastException. For example, suppose you want to keep a List of Lists (using the interface List from the Java 2 collections framework). When you Object myObject = masterList.get(0); }
> myref = (myInterface) myObject(); > It seems that not all methods from the interface must be included in the object ...?? > I appreciate your help. Thanks > Dirk
Replies: |
Sponsored Links
|