The Artima Developer Community
Sponsored Link

Java Buzz Forum
Friday Java Quiz: Generics

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Friday Java Quiz: Generics Posted: May 30, 2008 8:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Friday Java Quiz: Generics
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

Today's quiz is inspired by the free Chapter of Joshua Bloch's Effective Java, 2nd Edition available from InfoQ.

There was a short time early last year when I used generics on the project, until I received the memo that said "We are using JDK 5 mainly for its runtime performance improvements. You can't actually use any of the JDK 5 language features." So my generics skills have rusted a little. The free chapter gave me a much needed refresher on generics.

Here's todays question:

Q: Will the following method compile?

public static <T extends Comparable<? super T>> T max(
        List<? extends T> list) {
    Iterator<T> i = list.iterator();
    T result = i.next();
    while (i.hasNext()) {
        T t = i.next();
        if (t.compareTo(result) > 0)
            result = t;
    }
    return result;
}

The answer is in the sample chapter. Go read it.

Read: Friday Java Quiz: Generics

Topic: The Remedy Previous Topic   Next Topic Topic: links for 2008-05-23 from PeopleOverProcess.com

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use