How to use the syntax of java generics
This article mainly introduces the relevant knowledge of how to use the syntax of java generics, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to use the syntax of java generics. Let's take a look at it.
Description
1. The syntax of a generic method includes a list of type parameters (in angle brackets), which appears before the method returns the type.
For statically generic methods, the type parameter must appear before the return type.
2. A generic method is a method that introduces its own type parameters.
This is similar to declared generic types, but the scope of type parameters is limited to declared methods. Static and non-static generic methods as well as generic numbers are allowed.
Example
Public class Util {public static boolean compare (Pair p1, Pair p2) {return p1.getKey (). Equals (p2.getKey ()) & & p1.getValue (). Equals (p2.getValue ());}} public class Pair {private K key; private V value; public Pair (K key, V value) {this.key = key; this.value = value } public void setKey (K key) {this.key = key;} public void setValue (V value) {this.value = value;} public K getKey () {return key;} public V getValue () {return value;}} this is the end of the article on "how to use syntax for java generics". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use the grammar of java generics". If you want to learn more, you are welcome to follow the industry information channel.