Search the courses, subjects, tracks, games and features, or jump straight to a page.
2 cards from this section. Quick, good the night before a test.
Define a list that holds integer values using Java generics.
Think about how to specify the type in the collection.
What would happen if you try to add a string to a List
Consider the type safety principle of generics.
What does List<String> list = new ArrayList<>(); accomplish?
Consider what data types are allowed in the list.
True or False: Generics allow for type safety in Java before runtime.
Think about when types are checked in the code.
Create a generic method that swaps two elements in an array. What will be your method signature?
Consider how you'd swap values in a basic array before applying generics.
How would you define a generic class that can store two elements of any type?
Think about how to accommodate two different types in the same class.
5 more questions in this section. Enroll free to practise them all.
Enroll free