Skip to main content

Not wild enough

Posted by daniel on January 16, 2004 at 7:22 AM PST

In our java-net
featured articles
, William Grosso finishes his look at generics in

Explorations: Wild cards in the Generics specification
. Although
Generics already introduce more flexibility when referring to type in a
method, this article shows you how to use wild cards when you "want to leave
the type parameter unbound, as a signal to the compiler that the exact
type isn't important."

Bill starts with this example.

public <T extends Animal> void print animals(Collection <T> animals) { 
  for (Animal nextAnimal: animals) { 

Notice that the parameter T is never used in the body of
the method. As a first application of wild cards, he replaces
T with ?

public void print animals(Collection <? Extends Animal> animals) { 
  for (Animal nextAnimal: animals) {

Among other benefits, he points out that this version of the code
expresses more clearly that the parameter is never used in the method. But
the fun continues. Suppose you have the class Dog that
extends the class Animal . Then, since a List
is a Collection you might wrongly assume that

is a subclass of
Collection. Bill clarifies this issue
and shows how wild cards can solve this problem with inheritance. He also
looks at the use of Wild cards in variable assignments.

Recent featured articles also include a PDF excerpt from Hans Bergsten's
recent book "JavaServer Pages, 3rd edition". In href="">
Working with XML Data, Bergsten shows you how to generate XML
responses with JP and how to process XML data.

Also in Java Today
, Andreas Schaefer has kicked off an interesting discussion with his
post Brain Teaser #1: the
same but not equal
. He presents you with the same challenge he had
to solve recently: given that the "class 'ABC' does not overwrite equals()
method and derives directly from java.lang.Objects and everything is pure
Java", how can two instances of ABC be the same but not equal?

For some of the finer points in retrieving data from relational
databases, check out Satya Komatineni's href="">The
Effective Use of Joins in Select Statements. He presents eleven
principles on using joins for those that are familiar with them. This is
not an introductory article."Principles 1 through 6 deal with how to use
the join construct to solve practical issues in retrieving data from
relational databases. [...] The second set of principles, 8 through 10,
deal with the general question of patterning a select statement. From an
OO perspective, the select statement is seen as a vehicle for retrieving
objects that are called 'primary entities.'"

Note: I used a new XML editor to create today's entry. It "corrected" spelling and words without asking. I have tried to catch all of the errors and apologize for any I may have missed. (Below Lego was changed to Leg and above OO was changed to O)

In today's
, Philip Brittan writes that href=""> The Rich Client Strikes
Back. He points to a JDJ article that argues "Microsoft is redefining
the application interface around rich clients, and if Java does not have
an answer, it faces being cut off from end users. The answer lies in
matching Microsoft's richness while trumping it on security." In the
feedback a reader asks Philip what is so unworkable about Swing.

Sue Spielman responds to Kathy Sierra's blog by adding that href=""> MID 2.0 - Fun yes, but not
just games . Sue is looking for "cool applications that can
integrate enterprise business data onto mobile devices and bring forth
another whole category of mobile enterprise applications."

John Mitchell updates the status of Mindstorm robots in href=""> Lego backs off from killing
Mindstorms. The press release from Lego seems to imply that the media
got the story wrong - but it may be just a reassessment based on the
community reaction.

Projects and Communities
, The JavaPedia
catalog of href="">
Frameworks and Libraries is growing. Follow the existing links or
add to the list of ten libraries and eighteen frameworks. Also, do you
still refer to printouts of the Java APIs or do you depend on Java docs
and/or your IDE. An O'Reilly sponsored href="">
Survey considers reference material for the Java APIs as they
rethink the design of Java in a Nutshell.

In today's java-net
News Headlines

Registered users can submit news items for the href=""> News Page using
our news submission
. All submissions go through an editorial review by news director
Steve Mallet before being posted to the site. You can also subscribe to
News RSS feed

Current and upcoming
Java Events

  • January 17 href=""> JUG
    Indonesia's JaMU (Java Meet Up) #6
  • January 20-23 LinuxWorld
  • February 2-5 EclipseCon

Registered users can submit event listings for the href=""> Events Page using our href=""> events submission
form. All submissions go through an editorial review before being
posted to the site.

Archives and Subscriptions: This blog is delivered weekdays as the
Today RSS feed
. All members can subscribe to the email
updates for the site at the href="">
java-net Mailing Lists page. You must be logged in to subscribe
the javanet_Daily and javanet_Weekly lists. Also, once this page
is no longer featured as the front page of
it will be archived along with other past issues in the href=""> Archive.