当前位置:网站首页>What is generics and how to use generics analysis
What is generics and how to use generics analysis
2022-06-28 13:39:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
1、 Generic
1: What is generics ?
Generics are broad types , It's also a data type , This data type can be any type , The type cannot be determined during writing , You must specify a specific type when creating an object , You can't specify , But there will be some mistakes .
Generics are compiler behavior , Only valid at compile time , If you can cross the compiler , Then generics make no sense .
2、 Generic classes
How to define generic classes ?
Add after class <>,<> You can write any length and any character in , Cannot be numeric .( It's usually used 26 Capital English letters indicate )
Generic classes < The specific type > Variable name = new Generic classes <>();
Code example :
3、 Generic interface
Implementation classes do not specify generic types when implementing generic interfaces In this case, the generic type can be specified when creating the implementation class object class UserServiceImpl<T> implements UserService<T> The implementation class specifies the generic type when implementing the generic interface Then the generic type will be determined class UserServiceImpl implements UserService<String>
Code example :
4、 Generic methods
Method This method is a generic method Static methods cannot use generic types declared in generic classes Because the generic type is determined when the object is created , Static methods exist before objects , If you want to use , Declare a generic type on the current static method public static < The generic type > void Method name ()
Code example :
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/150701.html Link to the original text :https://javaforall.cn
边栏推荐
- Jerry's wif interferes with Bluetooth [chapter]
- Mysql database literacy, do you really know what a database is
- 腾讯云国际云服务器登录之后没有网络,如何排查?
- Google Earth engine (GEE) - Global organic soil area of FAO (1992-2018)
- 再談exception——异常拋出時會發生什麼?
- Elastic box auto wrap demo
- ThreadLocal的简单理解
- Idea global search shortcut settings
- (original) [Maui] realize "floating action button" step by step
- 新品体验:阿里云新一代本地SSD实例i4开放公测
猜你喜欢
![(original) [Maui] realize](/img/76/d79b9cf4ed44870bb20a189315def9.jpg)
(original) [Maui] realize "floating action button" step by step

Elastic box auto wrap demo

PHP crawls web pages for specific information

The counter attack story of Fu Jie, a young secondary school student: I spent 20 years from the second undergraduate to the ICLR outstanding Thesis Award

Align content attribute in flex layout

895. longest ascending subsequence

做一个墨水屏电子钟,炫酷!

Google Earth engine (GEE) - Global organic soil area of FAO (1992-2018)

全志V853芯片 如何在Tina V85x平台切换sensor?

排序
随机推荐
Jupyter notebook中添加虚拟环境
Zhongang mining focuses on the fluorine chemical industry and lays out the new energy industry chain
Yii2 writing the websocket service of swoole
PHP根据年月获取月初月末时间
Kubernetes 深入理解kubernetes(一)
The English translation of heartless sword Zhu Xi's two impressions of reading
In the past four years, the number of users exceeded 100 million, and sun Ge led the wave field to a new high
Mobile web training day-1
Other domestic mobile phones failed to fill the vacancy of Huawei, and apple has no rival in the high-end mobile phone market
2.01 backpack problem
PHP crawls web pages for specific information
再谈exception——异常抛出时会发生什么?
Jeecg 官方组件的使用笔记(更新中...)
(原创)【MAUI】一步一步实现“悬浮操作按钮”(FAB,Floating Action Button)
《蛤蟆先生去看心里医生》阅读笔记
Latest summary! 30 provinces announce 2022 college entrance examination scores
Template_ Large integer multiplication
Hubble数据库x某股份制商业银行:冠字号码管理系统升级,让每一张人民币都有 “身份证”
Centos7 - installing mysql5.7
Fs7022 scheme series fs4059a dual two lithium battery series charging IC and protection IC