Generics and Comparators Flashcards
What are the 4 different types of access levels for class methods or member variables?
public
protected
no modifier
private
Who can access public methods or member variables?
- The Class
- The SubClasses.
- The package.
- The World
Who can access the protected methods or member variables?
- The Class.
- The Subclasses
- The Package
Who can access the private methods or member variables
- The class
What term refers to things such as public, private, and protected?
Modifier
What is a modifier give 4 examples.
A modifier is a declaration of the access level.
Ex: public, private, protected, no modifier
When no modifier has been declared who does the default modifier allow to access member variables or methods?
- The class.
2. Classes within the package.
Give an example of a common generic class that we use all the time.
ArrayList
What is a generic placeholder?
During the class implementation you can use to create a generic placeholder that will be filled in during construction.
How do generic types treat class inheritance?
They ignore it.
Ex. An ArrayList is NOT an ArrayList
Even though a Triangle is a Shape.
How do method signatures apply to generic placeholders?
The method signature must specify a type and the method cannot be called on the derived classes of that type.
Ex:
public void doStuff(ArrayList x){….}
ArrayList triList ;
ArrayList shapeList;
doStuff(triList) is ILLEGAL
doStuff(shapeList) is Allowed.
How can we create method signatures that will allow a generic type and any of its subclasses to be passed as parameters?
Use wildcards
public void doStuff(ArrayList x)
ArrayList triList ;
ArrayList shapeList;
doStuff(triList) is Allowed
doStuff(shapeList) is Allowed.
What is an upper-bounded wildcard?
extends Shape>
Refers to Shape and any of it’s derived classes.
Ex: Shape, Circle, Triangle
What is a lower-bounded wildcard?
super Triangle>
Refers to Triangle and any that is a superclass of it.
Ex: Triangle, and Shape.
If List and List do not have List as their parent what is their parent?
List> is the parent.