aspose file tools*
The moose likes Beginning Java and the fly likes Is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is "array of interface" supported in Java ?" Watch "Is "array of interface" supported in Java ?" New topic
Author

Is "array of interface" supported in Java ?

Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
Hi ranchers !
Is such thing as
array of interface
supported in Java ?

I understand that I can create array of Object and then cast
each element to my interface.
I understand also that in incoming java 1.5 will be generics.
(that not only make the language more complex, but
(prabably) can help in the case)
I understand also about array of base class, but I wish exactly
array of interface,
(the elements of the array can be without common base class,
(only Object can help here, because it alwais base class for all))
;-)
Really I think that such thing is not implemented in Java, but... ?
Thank you !
[ November 30, 2003: Message edited by: Igor Ko ]
[ November 30, 2003: Message edited by: Igor Ko ]
[ November 30, 2003: Message edited by: Igor Ko ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

In Java, you can define an array of any type. As interfaces are types, you can indeed define arrays of interfaces -- i.e.,
Cloneable[] c = new Cloneable[10];
declares and constructs an array that can hold ten objects that implement the "Cloneable" interface.


[Jess in Action][AskingGoodQuestions]
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
Thank you. It works !
[ December 01, 2003: Message edited by: Igor Ko ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is "array of interface" supported in Java ?
 
Similar Threads
page 159 of Sierra/Bates book
Java still Java?
Calling main() method
A "Class" problem, someone help me...
JAVA RAndom Numbers