• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generic Method

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While running the following script I am getting,
AnimalDoctorGeneric.java:12: type ArrayList does not take parameters
List<Dog> dogs = new ArrayList<Dog>();

What is the problem? please help

import java.util.*;
abstract class Animal {
public abstract void checkup();
}
class Dog extends Animal {
public void checkup() {
System.out.println("Dog checkup");
}
}
public class AnimalDoctorGeneric {
public static void main(String[] args) {
List<Dog> dogs = new ArrayList<Dog>();
}
}
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code compiles fine. I tried it.

Maybe you are not using Java 1.5 compiler???
 
Biby Thoms
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)


Is it correct version?
 
Biby Thoms
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help ...still i have the same problem.
everything is verison 5.
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Biby Thoms:
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)


Is it correct version?



You are looking at the version of JRE (jave runtime env.) which is 1.5 and is fine. However, to compile your program, you need JDK (java development kit), which has the compiler that you execute using 'javac'. Check the version of javac.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you were using an incorrect version of javac, then you would get a simple syntax error and not the error you got.

I think the more likely cause is that you've create an ArrayList.java class that is either in your current directory or in your CLASSPATH, and the compiler is complaining because it is not defined with type parameters.

I tried an experiment where I took your code and put an ArrayList.java class in the same directory that was defined without type parameters, and got the error that you did.
 
Biby Thoms
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Keith,

Thank you very much. You are correct...There was a class file called ArrayList.class.

Thank you..and everybody else those who tried to help me.
 
reply
    Bookmark Topic Watch Topic
  • New Topic