Entrance Exams
Govt. Exams
List
Upper bounded wildcards (? extends Number) are read-only. You cannot add elements because the compiler doesn't know the exact subtype.
List[] array = new List[10];
You cannot create arrays of generic types because of type erasure. The compiler prevents this with a compilation error.
Wildcards (?) represent an unknown type. Upper bound (? extends T) accepts T or its subtypes. Lower bound (? super T) accepts T or its supertypes.
Type erasure is a mechanism where the Java compiler removes all generic type information during compilation, converting generic code to its raw type equivalent.
The correct syntax for a generic method is: access_modifier <T> returnType methodName(T parameter). The type parameter <T> must come before the return type.
List list = new ArrayList();
list.add("Java");
System.out.println(list.get(0).length());
"Java" has 4 characters. The generic type ensures the element is a String, so .length() method is available without casting.
<T> is the standard syntax for declaring a generic type parameter in Java classes.
Generics enable type safety at compile time and eliminate the need for explicit type casting, reducing runtime errors.
getMetaData() on ResultSet returns ResultSetMetaData which provides column information. getColumnCount() and getColumnName() are methods of ResultSetMetaData used to retrieve structure details.
DataSource with connection pooling frameworks (HikariCP, C3P0) efficiently manages connections by reusing them, reducing overhead. Direct getConnection() calls create new connections each time, which is inefficient for high concurrency.