Home  >  Article  >  Java  >  What are the characteristics of java generic methods

What are the characteristics of java generic methods

WBOY
WBOYforward
2023-04-15 10:19:051211browse

1. Description

The relationship between public and return value is very important and can be understood as a universal method. Only the described methods are generic methods, and the member methods used in generic classes are not generic methods.

This method will use generic T, and generic T can be used at this time. Just like the definition of generics, T here can be written as any identifier. Common parameters such as T, E, K, V, etc. are usually used to represent generics.

2. Example

class DataHolder{     
T item;        
  public void setData(T t) {  
      this.item=t;   
  }      
  public T getData() {   
     return this.item;  
   }        
     /**      * 泛型方法      * @param e      */   
   publicvoid PrinterInfo(E e) {    
       System.out.println(e); 
    } 
}

What is Java

Java is an object-oriented programming language that can write desktop applications, Web applications, Distributed systems and embedded systems applications.

That’s it for “What are the characteristics of Java generic methods”? Thank you for reading. If you want to know more about the industry, you can pay attention to this site. The editor will output more high-quality practical articles for everyone!

The above is the detailed content of What are the characteristics of java generic methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete