• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

beerExpert.java uses unchecked or unsafe operations

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings to the Group,

I am on page 82 of Head First and am compiling BeerExpert.

C:\MyProjects\beerV1\src\com\example\model\javac BeerExpert.java

Note: BeerExpert.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

After recompiling with javac -Xlint parameter I get:

warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
brands.add("Jack Amber");

I get the same error for Red Moose, Jail Pale Ale and Gout Stout.

A BeerSelect.class file is still created but then when I go to page 84 and modify BeerSelect.java and compile it I get:

package com.example.model does not exist.

The source for BeerSelect.java is:

package com.example.web;

// version 2 of the servlet page 84

import com.example.model.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

public class BeerSelect extends HttpServlet {

public void doPost (HttpServletRequest request,
HttpServletResponse response)

throws IOException, ServletException {

response.setContentType ("text/html");

PrintWriter out = response.getWriter();

out.println("Beer Selection Advice<br>");

String c = request.getParameter("color");


BeerExpert be = new BeerExpert();

List result = be.getBrands(c);

Iterator it = result.iterator();

while (it.hasNext()) {

out.print("<br>try: " + it.next());
}
}}


The source for BeerExpert.java is:

package com.example.model;

import java.util.*;

public class BeerExpert {

public List getBrands(String color) {

List brands = new ArrayList();

if (color.equals("amber")) {

brands.add("Jack Amber");
brands.add("Red Moose");
}

else {

brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}

return (brands);

}
}

Before I modified it as on page 84 I successfully compiled BeerSelect.java
I was able to display the Beer Selection Page then after clicking on a color and Submit Query I received a page that read Beer Selection Advice and nothing else.

I deleted both the BeerSelect and Beer Expert class files and started over recompiling them when I received the errors above.

Since successfully display the messages on the pages in the previous paragraph I have not changed any environment variables.

This is on Tomcat 5.5.4 JDK 1.5.0

Any help greatly appreciated.

Thanks,

Jerry Bustamente
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply put. Java 1.5 has Generics. The message you get is just warning, it still compiles.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generics is about type safety for your Collection, and some more. But with Collections you basically tell it what type of objects you can put into the Collection. When you have code that does not say what type you can put in the Collection, it will allow you to do this, which is the 1.4 and before way, but it will give you a warning. The reason why it won't cause an error is to allow for backwards compatibility.

Mark
 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot Mark!

Jerry Bustamente
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to Java In General (beginner) forum.
 
What's gotten into you? Could it be this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic