The Source for Java Technology Collaboration
User: Password:



   

Java Tech: Generics and You Java Tech: Generics and You

by Jeff Friesen
11/10/2005

Contents
Take the Test
Review and Compare
Conclusion
Resources
Answers to Previous Homework

How much do you know about generics? Based on your amount of generics knowledge, are you comfortable with having to maintain another developer's generified code, should your project manager tell you to do so? Perhaps you have not taken the time to determine how much you know about generics and how much you still have to learn. If you would like to assess your generics I.Q., you might find this article a helpful test of your generics knowledge.

Note: This article bases its content on a very useful and extensive generics FAQ that I discovered a couple of months ago. After you finish this article, do yourself a favor by checking out the FAQ, listed in the Resources section at the end of the article.

Take the Test

This section presents a test on several generics concepts. The test's 20 questions are a mixture of fill in the blank, true/false, multiple choice, and long answer. Take all the time you need to complete this test, but resist the urge to peek at the answers (which I present in the next section) until you finish. The test begins now.

  1. Generics identifies language features for defining and using ________________ and ________________.

  2. What is a parameterized type?

  3. How does generics promote type safety?

  4. Which of the following reference types cannot be generic?

    1. Anonymous inner class
    2. Interface
    3. Inner class
    4. All of the above
  5. True or false: Set<Object> is the supertype of Set<String>.

  6. What is a type parameter?

  7. A ________________ describes a family of types and is used as a type parameter.

  8. How is a concrete parameterized type different from a non-concrete parameterized type?

  9. True or false: parameterized types have type parameters.

  10. Which syntax would you use to express a wildcard with a lower bound of some type?

    1. ?
    2. ? extends type
    3. ? super type
    4. None of the above
  11. Identify those types that cannot be used as type arguments.

  12. Why can you not derive (directly or indirectly) generic classes from Throwable?

  13. What is type erasure?

  14. Identify the tasks performed by type erasure.

  15. True or false: The parameterized types List<Date> and List<?> share the same runtime type.

  16. The opposite of type erasure is known as ________________.

  17. Which overloaded method is called by the following program?

    // Overload.java
    
    import java.util.Date;
    
    public class Overload
    {
       public static void someOverloadedMethod (Object o)
       {
          System.out.println
            ("call to someOverloadedMethod(Object o)");
       }
    
       public static void someOverloadedMethod (Date d)
       {
          System.out.println
            ("call to someOverloadedMethod(Date d)");
       }
    
       public static <T> void methodCaller (T t)
       {
          someOverloadedMethod (t);
       }
    
       public static void main (String [] args)
       {
          methodCaller (new Date ());      
       }
    }
    
  18. What is an "unchecked" warning message?

  19. When the compiler reports an unchecked or unsafe operation, it also tells you to recompile with the ________________ option to obtain details.

  20. True or false: the code fragment System.out.println (o instanceof Set<String>); will compile.

Pages: 1, 2

Next Page » 

View all java.net Articles.

 Feed java.net RSS Feeds