The project contains some notes and code examples to upgrade to Java 11 and to pass exam 1Z0-817.
- Ambiguity errors that involve overloading methods:
class MyGenClass<T, V> {
T ob1;
V ob2;
void set(T o) {
ob1 = o;
}
void set(V o) {
ob2 = o;
}
}
// these two overloaded methods are ambiguous and won't compile
// because type erasure results in both to
// void set(Object o) {}
- Type parameter cannot be instantiated:
class Gen<T> {
T ob;
Gen() {
ob = new T(); // Illegal!
}
}
- A generic class cannot extend Throwable. It is not possible to create generic exception classes.
- Generic types can't be used by static members of classes:
class Wrong<T> {
// no static variables of type T
static T ob;
// no static methods that use T
static T getOb() {
return ob;
}
}
- You cannot create array of type T:
...
T[] vals = new T[10]; // incorrect
- You cannot create array of type-specific generic references:
MyClass<Integer> arr[] = new MyClass<Integer>[5]; // incorrect
but this OK:
MyClass<?> gens[] = new MyClass<?>[10];
- Lambda expression has access to instance and static members defined by enclosing class
- Lambda expression has access to local variable and can use it, as for as this variable is effectively final. So neither inside lambda expression or outside this variable must not be modified, otherwise code won't compile
The capacity is the number of buckets(used to store key and value) in the Hash table , and the initial capacity is simply the capacity at the time Hash table is created.
The load factor is a measure of how full the Hash table is allowed to get before its capacity is automatically increased.
-
Iterator offers standardized way of accessing the elements within a collection, one at a time.
-
Spliterator is iterator that provide support for parallel iteration.
-
ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements
-
RandomAccess interface contains no members. However, by implementing this interface, a collection signals that it supports efficient random access to its elements.
-
SortedMap interface extends Map. It ensures that the entries are maintained in ascending order based on the keys
-
NavigableMap interface extends SortedMap and declares the behavior of a map that supports the retrieval of entries based on the closest match to a given key or keys