What does the syntax mean in Java?

后端 未结 4 2020
有刺的猬
有刺的猬 2021-01-30 02:27

I\'ve quickly googled for an answer but could not not find/think of accurate search parameters.

I am teaching myself Java, but can\'t seem to find the meaning of a certa

4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 03:09

    Here denotes the type parameter of Node class .The type parameter defines that it can refer to any type (like String, Integer, Employee etc.). Java generics have type parameter naming conventions like following:

    1. T - Type
    2. E - Element
    3. K - Key

    4. N - Number

    5. V - Value

    For example take the following scenerio

    public class Node{
       E elem;
       Node next, previous;
    }
    class Test{
       Node obj = new Node<>();
    }
    

    For the above scenerio, in background the Node class 'E' will reference the String type and class will be look like following

    public class Node{
       String elem;
       Node next,previous;
    }
    

    Not only String you can also use Integer,Character,Employee etc as a type parameter.

    You can use generics with Interface,method and constructor too.

    For more about generics visit these:

    https://www.journaldev.com/1663/java-generics-example-method-class-interface https://www.javatpoint.com/generics-in-java

提交回复
热议问题