• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic Method

 
Biby Thoms
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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>();
}
}
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Please help ...still i have the same problem.
everything is verison 5.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3715
10
  • Mark post as helpful
  • send pies
  • 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.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic