Game Development Reference
In-Depth Information
}
public boolean collide (Actor actor) {
// Java statements to process for collision
detection
}
}
So with the java.util ArrayList class that we looked at earlier, the technical class
definition is as follows:
public class ArrayList<E> extends AbstractList<E>
implements List<E>
The ArrayList<E> class also implements RandomAccess, Cloneable, and Serializ-
able, but we will not be using those at this time so I am just showing you the parts of
the ArrayList<E> class definition that pertain to what we will be learning during this
chapter, not the full public class ArrayList<E> extends Ab-
stractList<E> implements List<E>, RandomAccess, Cloneable,
Serializable class definition, as you would see if you look at the Java class docu-
mentation for the ArrayList<E> class online.
It is important to notice that the .addAll() , .removeAll() and .clear() method calls
that we will use with the ArrayList<E> class are implemented because the List<E>
Java interface demands that they be implemented, so that is the connection between the
classes and why we will specify the declaration of the ArrayList<> object using this
code:
private List< Actor > CURRENT_CAST = new ArrayList<>();
You may be wondering why we will not need to explicitly specify the Actor object
type on both sides of this declaration and instantiation statement. Prior to Java 7, you
would have needed to specify your Actor object type on both sides of this statement,
inside of the ArrayList<>() constructor method call. So, if you are writing game code
that needs to be compatible with Java 5 and Java 6, you would code this statement us-
ing the following line of Java code:
private List< Actor > CURRENT_CAST = new ArrayList< Actor >();
Now that we have learned what a Java interface is, let's take a look at the List<E>
public interface in detail.
Search WWH ::




Custom Search