Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard Interfaces

Tags:

java

interface

I've used Java for some time and I keep hearing about interfaces such as Cloneable, Iterable and other X-ables.

I was wondering if there is a list somewhere of all of these and more importantly - which ones do you regularly use day-to-day?

For example, I've read that Cloneable is considered badly written and isn't widely used.

like image 385
Amir Rachum Avatar asked May 18 '10 20:05

Amir Rachum


1 Answers

The Interfaces you're most likely to implement are:
java.lang.Comparable
java.lang.Runnable
java.io.Serializable

Interfaces that you're most likely to call methods on but not implement yourself are:
java.lang.Appendable (StringBuffer / StringBuilder / Writers)
java.lang.CharSequence (String / StringBuffer / StringBuilder)
java.lang.Iterable (Collections, either explicitly or with for Blah blah : List<Blah>)
java.lang.Readable (Readers)
java.io.Closeable (Streams)
java.io.Flushable (Streams)
java.util.Collection (Collections)
java.util.Deque (Collections)
java.util.List (Collections)
java.util.Map (Collections)
java.util.Set (Collections)

Interfaces that are most likely to blow up in your face:
java.lang.Cloneable

Edit: Whoops, Throwable's not an interface.

Usually, it's better to write a Copy Constructor rather than use a clone() method.

like image 136
Powerlord Avatar answered Nov 09 '22 06:11

Powerlord