Very basic question - What are the Generics for ....

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rssx
Posts: 17
Joined: Wed Dec 05, 2012 6:49 am
antibot: No, of course not.

Very basic question - What are the Generics for ....

Post by rssx » Mon Mar 11, 2013 5:28 pm

What are the datatype generics for the Classes:
I get these warning messages regarding declaration:

private static IntervalXYDataset createReturnDataset(String title, ArrayList X, ArrayList Y)
Now I have tried to change this as follows
private static IntervalXYDataset createReturnDataset(String title, ArrayList<int> X, ArrayList<int> Y)
private static IntervalXYDataset createReturnDataset(String title, ArrayList<double> X, ArrayList<double> Y)
and neither work
Error Message:
ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
line 484 Java Problem

DefaultIntervalXYDataset;
XYIntervalSeriesCollection.

HistogramDataset;
SimpleHistogramDataset;
TimePeriodValuesCollection;
TimeSeriesCollection;

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Very basic question - What are the Generics for ....

Post by John Matthews » Wed Mar 13, 2013 1:50 pm

Generic parameters allow compile-time type checking. Primitive types, such as int and double, are not valid generic parameter types. Instead, use the corresponding wrappers types, such as Integer or Double. For more flexibility, code to the interface type, e.g. List<Integer> or List<Double>.

Locked