Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the syntax of java generics

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report