0

This is a code i found for Egit

I am new to the usage of PlotCommitList<L extends PlotLane>.

  1. what is the term used for it?
  2. what does it signify or mean to the compiler?

public class PlotCommitList<L extends PlotLane> extends RevCommitList<PlotCommit<L>> {

Naveen Babu
  • 1,584
  • 1
  • 14
  • 35
  • 3
    It's not a duplicate of that question – artbristol Nov 05 '12 at 11:02
  • 1
    @Tichodroma the diamond operator is <> without anything inside - so this question is not a duplicate as it asks about the generic syntax for Java 5+. – nd. Nov 05 '12 at 11:02
  • The title shows the diamond operator and the initial question (before all these edits) didn't make it clearer. – maba Nov 05 '12 at 11:04
  • @maba And that's why we have the option of editing and voting to reopen. =) – J. Steen Nov 05 '12 at 11:05
  • 1
    @J.Steen Yes but then it should probably be closed with a link to another Java Generic SO question that answers this question. – maba Nov 05 '12 at 11:05
  • 1
    This is a possible duplicate: http://stackoverflow.com/questions/6607550/what-does-angle-brackets-mean-in-java – maba Nov 05 '12 at 11:17
  • it means that class is 'generic', it can be a pretty big lecture so I suggest you to read a book about it but you can find some information about it [here](http://docs.oracle.com/javase/tutorial/java/generics/) – Bela Vizer Nov 05 '12 at 11:02
  • Its called [generic](http://docs.oracle.com/javase/tutorial/java/generics/index.html) which introduced in java 1.5. – Subhrajyoti Majumder Nov 05 '12 at 11:01

1 Answers1

3

The <> operator is used to specify classes in generic templates.

Image a generic "list". In Java up to 1.4, a "list" could only contain generic Objects. If you wanted to make sure you only kept Strings in your list you had to use a lot of casting and helper methods, which made the code barely readable.

Java 5 introduced generics, which solves the problem - you can create a template class "list of ", and parametrise the class used as parameter or return value.

Furthermore, you can use the <L extends ...> and <L super ...> to limit the range of classes your template works with, have multiple classes as parameters <class1,class2> and combine things up <class1,class2<class3>> at will.

There is a very good tutorial at http://www.javacodegeeks.com/2011/04/java-generics-quick-tutorial.html

thedayofcondor
  • 3,860
  • 1
  • 19
  • 28