This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is "array of interface" supported in Java ?

 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. It works !
[ December 01, 2003: Message edited by: Igor Ko ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic