1

This question is an exact duplicate of:
What does <> (angle brackets) mean in Java?

I am reading about AsyncTask in Android. I have this example code:

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile(urls[i]);
             publishProgress((int) ((i / (float) count) * 100));
         }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }

And it is supposed to be called with:

new DownloadFilesTask().execute(url1, url2, url3);

I can't understand what <URL, Integer, Long> means. I have seen them in some other classes like String<> but I don't know what is the purpose of them.

Community
  • 1
  • 1
Andres
  • 6,080
  • 13
  • 60
  • 110
  • 1
    @Aidanc - Hover over downvote button: *Research Effort*. Not only is a dupe, any beginners book on Java covers it as well as the basic tutorials from Oracle. – Brian Roach Apr 24 '12 at 18:00

2 Answers2

2

It defines the types of generics.


For example:

List<Integer> list;

You declare a variable of class List. But List is declared like this, if I'm right:

public interface List<T> extends Collection<T>

The T is a placeholder for a type that the user of this class can define. In my example, I chose to fill in the T with Integer. In this case it means I'll have a List of Integers.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
0

it is http://docs.oracle.com/javase/tutorial/java/generics/generics.html

but basically what is means is you have some container like

List<> aList

and the compiler needs to know what type it is holding so you specific the type associated with the container

List<String> aList
nate_weldon
  • 2,289
  • 1
  • 26
  • 32