-2

I have this code for a class that represent a element in a list

public class Element<T>{
   Element<T> next;
   Element<T> previous;
   T info;
}

I have some ideas but I actually don't figure out the full meaning of the above declaration. And have some hard times to search for an explanation of this technique.

koalaok
  • 5,075
  • 11
  • 47
  • 91
  • 1
    https://docs.oracle.com/javase/tutorial/java/generics/types.html – superfell Jan 07 '16 at 23:07
  • These are generics. Your usage is correct. Google for it, as this question is to broad. – Marcinek Jan 07 '16 at 23:07
  • 1
    @SotiriosDelimanolis: I suppose so, though I have evolved the opinion that StackOverflow might have become overly hostile for at least some "entry level questions" even if duplicated. – scottb Jan 07 '16 at 23:21
  • 1
    Sorry but without knowing it is called generics. It is not easy to google. Or search in SO questions – koalaok Jan 07 '16 at 23:22
  • @koalaok: You're right, it's hard to google something that you don't really know the name of, especially if the thing uses special characters. And that's perfectly ok. You learned now :) Btw, the characters are called "angle brackets". – Lukas Eder Jan 07 '16 at 23:34

2 Answers2

2

The name of the class is Element

<T>

indicates that it's a generic class. When you use it you have to parameterize it:

Element <Object> e = new Element<Object>();

Every occurrence of

<T>

in the class, will be replaced with Object (you could put whatever class type you want instead of Object, but not a primitive type)

Massi A
  • 30
  • 5
1

The <T> is a generic type, the class name is simply Element. Generics are a bit of a complex topic, but the code you've posted looks valid.

dimo414
  • 47,227
  • 18
  • 148
  • 244