What does <T extends mean?

后端 未结 7 1557
庸人自扰
庸人自扰 2020-12-12 22:00

I have seen a method like shown below:

protected  T save( T Acd, boolean en) {

What does it do? What is these type of

相关标签:
7条回答
  • 2020-12-12 23:03

    This is called generics in Java.

    Official explanation:

    In a nutshell, generics enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs. The difference is that the inputs to formal parameters are values, while the inputs to type parameters are types.

    Informally:

    Strongly typed languages like Java cause more errors show up at compile time instead of runtime. This is a good thing. But it causes code duplication. To mitigate this generics was added to Java.

    0 讨论(0)
提交回复
热议问题