简体   繁体   English

“公共抽象类SampleAdapter”是什么意思 <T extends Adapter> 扩展ViewGroup”?

[英]What's th mean by “public abstract class SampleAdapter <T extends Adapter> extends ViewGroup”?

I am not getting meaning by 我的意思不是

public abstract class  SampleAdapter <T extends Adapter> extends ViewGroup

What does it do? 它有什么作用? In general we perform normal inheritance, but here something extended form. 通常,我们执行正常的继承,但是这里有一些扩展形式。 can any body suggest me? 有人可以建议我吗?

thanks 谢谢

This declares a class SampleAdapter that: 这将声明一个类SampleAdapter

  • has public visibility 具有公众知名度
  • is abstract ; 抽象的 ; it cannot be instantiated directly; 它不能直接实例化; it must be be used as a base class. 它必须用作基类。
  • is generic ; 通用的 ; it must be parameterised by some type T that is a sub-class of Adapter . 它必须由Adapter的子类T进行参数化。
  • inherits from ViewGroup . ViewGroup继承。

T extends Adapter : T extends Adapter

The class SampleAdapter takes a class parameter T that should extend Adapter SampleAdapter类采用扩展Adapter的类参数T

example : 例如

ArrayList A = new ArrayList<String>();

String is parameter for ArrayList. String是ArrayList的参数。

SampleAdapter A = new SampleAdapter<parameterClass> ();

parameterClass is parameter for SampleAdapter (which is T) and it must extend Adapter : parameterClass是SampleAdapter的参数(它是T),它必须扩展Adapter

public class parameterClass extends Adapter{//must extend Adapter

As for abstract , it says that class SampleAdapter is a class that can't be instantiated directly but rather must be extended by another class. 至于abstract ,它表示SampleAdapter类是一个不能直接实例化的类,而必须由另一个类扩展。

The thing inside the < > section is associated a concept called "generics". < >部分中的内容与一个称为“泛型”的概念相关联。 It's a feature introduced in Java from Java 5 and forward. 这是Java 5及更高版本在Java中引入的功能。 You can read more here . 您可以在这里阅读更多内容。

abstract is referring to a class that can't be instantiated directly, usually because of some methods that need to be implemented in an extending class. abstract是指无法直接实例化的类,通常是因为某些方法需要在扩展类中实现。

You'll have to implement those abstract methods in the subclass, otherwise your code won't compile. 您必须在子类中实现这些abstract方法,否则您的代码将无法编译。

abstract means that the SampleAdapter class cannot have any objects, <T extends Adapter> means, that the SampleAdapter class is used as a container for objects of any class, that extends Adapter . abstract表示SampleAdapter类不能有任何对象, <T extends Adapter>表示SampleAdapter类用作扩展Adapter的任何类的对象的容器。 Hope this helps. 希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 做什么<t extends mean?< div><div id="text_translate"><p> 我见过如下所示的方法:</p><pre> protected &lt;T extends ABC&gt; T save( T Acd, boolean en) {</pre><p> 它有什么作用? 这些类型的方法声明在 Java 中称为什么?</p></div></t> - What does <T extends mean? 在 Java 的泛型类中,“T 扩展垃圾”是什么意思? - What does "T extends Junk" mean in a generic class in Java? 对于抽象类A是否有更好的解决方案 <T extends A> ? - Is there any better solution for abstract class A<T extends A>? 公共类PriorityQueue <T extends Comparable<T> &gt; - public class PriorityQueue <T extends Comparable<T>> `class 之间的实际区别是什么<t extends a> { }` 和一个使用 A? 的 `class { }`</t> - What's the practical difference between `class <T extends A> { }` and a `class { }` that uses A? 这是什么意思List &lt;Class <? extends DataType> &gt;? - What does this mean List < Class <? extends DataType>>? 什么课 <? extends ParentClass> 意思? - What does Class<? extends ParentClass> mean? 从另一个抽象类扩展的抽象类的重要性是什么 - What is the importance of abstract class that extends from another abstract class 类有什么区别<? extends T>和班级<? extends ?>在爪哇? - What is the difference between Class<? extends T> and Class<? extends ?> in Java? 为什么我不能在我的“公共 class 适配器扩展 PagerAdapter”到 MainActivity2s - Why I cant make an intent in my “public class adapter extends PagerAdapter” to MainActivity2s
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM