-3

I am working on a tutorial and the example code has the following line:

public class GreenAdapter
   extends RecyclerView.Adapter<GreenAdapter.NumberViewHolder> {

How does <GreenAdapter.NumberViewHolder> fit in, what does the <> syntax mean?

Aubin
  • 14,617
  • 9
  • 61
  • 84
Chris Starling
  • 422
  • 6
  • 20

1 Answers1

1

From the code it seems you are working in Android.

<> is the syntax for widely used feature in java called Java Generics introduced in Java 5.0. They extend Java's type system to allow “a type or method to operate on objects of various types while providing compile-time type safety.”

For an example: if you have had a look at Collections Apis of java, you will find same class with different generics type passed to it. Have a look at ArrayList<> , HashMap<> and other collection apis.

With whatever type you pass , class will start working on that type only and will take care of type safety. So I'll advice you to first go through a very basic tutorial of Java generics before proceeding any further.

Here is the link for very very basic tutorial for Java generics that will clear some air: https://www.tutorialspoint.com/java/java_generics.htm

And then if you want to get a deeper understanding of this, read some reference books over this topic. Have a good day :)

Rohit Khurana
  • 166
  • 12