JAVA generic methods and static method generics

Source: Internet
Author: User

/*

Review Spare:
Generic methods and static methods generic generic class definitions are valid for the entire class if the object of the generic class is used by the method, then all types that are to be manipulated are fixed so that different methods can manipulate different types and the types are undefined Generics can then be defined on a method by a static method generic: A static method cannot access a generic defined on a class if the application data type for a static method operation is undefined, you can define the generic on the method*/classDemo<t>{ Public voidmethod (T-t) {System. out. println ("Method:"+t); } Public Static<W>voidStaticmethod (w) {System. out. println ("Staticmethod:"+W); } Public<K>voidShow (k k) {System. out. println ("Show:"+k); } Public<Q>voidprint (q q) {System. out. println ("Print:"+q); }}classtestdemo{ Public Static voidmain (String [] arags) {Demo<Double> d =NewDemo<double>(); D.method (3.4); D.staticmethod (true); D.show ("haha"); D.print (NewInteger (4)); }}

JAVA generic methods and static method generics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.