wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generic Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generic Method" Watch "Generic Method" New topic
Author

Generic Method

Biby Thoms
Ranch Hand

Joined: Jan 10, 2006
Posts: 48
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>();
}
}


Thanks<br />Biby Thoms
Surendra Kumar
Ranch Hand

Joined: Jul 04, 2006
Posts: 235
This code compiles fine. I tried it.

Maybe you are not using Java 1.5 compiler???
Biby Thoms
Ranch Hand

Joined: Jan 10, 2006
Posts: 48
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

Joined: Jan 10, 2006
Posts: 48
Please help ...still i have the same problem.
everything is verison 5.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3313
    
    7
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.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jan 10, 2006
Posts: 48
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generic Method