This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic error!

 
Robert Bonslater
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile my code it produces:

jakarta-tomcat-5\webapps\begjsp-tourism\WEB-INF\classes\com\wrox\tourism\db\Even
tDAO.java:217: warning: [unchecked] unchecked call to add(E) as a member of the
raw type java.util.ArrayList
list.add(event);
^
I thought I defined the gerneric types. What do I need to do to list.add(new Attraction(attraction));?
Here is the piece of code:

public Collection findAll() {

PreparedStatement ps = null;
ResultSet rs = null;
ArrayList list = new ArrayList();

String sql = "SELECT * from attraction ";

try {

if (con.isClosed()) {
throw new IllegalStateException("error.unexpected");
}

ps = con.prepareStatement(sql);
rs = ps.executeQuery();

while(rs.next()) {

Attraction attraction = new Attraction();
attraction.setUserId(rs.getString(1));
attraction.setPassword(rs.getString(2));
attraction.setName(rs.getString(3));
attraction.setDescription(rs.getString(4));
attraction.setWebSite(rs.getString(5));
attraction.setAddress(rs.getString(6));

list.add(new Attraction(attraction));

}

return list;
 
K Riaz
Ranch Hand
Posts: 375
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing list.add(new Attraction(attraction)) to list.add(attraction)
 
Robert Bonslater
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, I also needed to use <Type_Name> tags after the array:

ArrayList<Attraction> list = new ArrayList<Attraction>();

Thanks
 
Liam Tiarnach
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any "generics" in your code...
The error state that you are using a raw non parameterized ArrayList...
If you want a generified ArrayList, then you have to include the generic parameters ( terminology anyone ? )...

now the ArrayList is set to take only Attraction types...

here is a link to Sun's Java Tutorial Generics Lesson...
http://java.sun.com/docs/books/tutorial/extra/generics/index.html

check it out so that you can learn what and how to use generics...

have fun...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic