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.

[prettify] 
public <T extends Animal> void print animals(Collection <T> animals) { 
  for (Animal nextAnimal: animals) { 
    System.out.println(nextAnimal); 
  } 
}
[/prettify]

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 ?

[prettify]
public void print animals(Collection <? Extends Animal> animals) { 
  for (Animal nextAnimal: animals) {
    System.out.println(nextAnimal); 
  } 
}
[/prettify]

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

 List
     
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="http://today.java.net/pub/a/today/2004/01/09/ch15XMLData.html">
Working with XML Data, Bergsten shows you how to generate XML
responses with JP and how to process XML data.


In
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="http://www.onjava.com/pub/a/onjava/2004/01/07/SQLJoins.html">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
Weblogs
, Philip Brittan writes that href="http://today.java.net/pub/wlg/910"> 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="http://weblogs.java.net/pub/wlg/911"> 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="http://weblogs.java.net/pub/wlg/913"> 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.


In
Projects and Communities
, The JavaPedia
catalog of href="http://wiki.java.net/bin/view/Javapedia/FrameworksAndLibraries">
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="http://www.zoomerang.com/survey.zgi?L222LTNYRMUFCW0BLL7RM3AC">
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="http://today.java.net/today/news/">java.net News Page using
our news submission
form
. All submissions go through an editorial review by news director
Steve Mallet before being posted to the site. You can also subscribe to
thejava.net
News RSS feed
.


Current and upcoming
Java Events
:

  • January 17 href="http://www.jug.or.id/JSPWiki/Wiki.jsp?page=Event"> 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="http://www.java.net/events">java.net Events Page using our href="http://today.java.net/cs/user/create/e"> 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
Java
Today RSS feed
. All java.net members can subscribe to the email
updates for the site at the href="https://java-net.dev.java.net/servlets/ProjectMailingListList">
java-net Mailing Lists page. You must be logged in to subscribe
to
the javanet_Daily and javanet_Weekly lists. Also, once this page
is no longer featured as the front page of
java.net
it will be archived along with other past issues in the href="http://today.java.net/today/archive/">java.net Archive.