English 中文(简体)
Java的一般模式做了哪些工作?
原标题:What does this Java generics paradigm do and what is it called?

I m 学习一些 Java课程,形式如下:


public 
abstract
class A <E extends A<E>> implements Comparable <E> {

   public final int compareTo( E other ) {
      //  etc
   }   
}

public 
class B extends A <B> {
   // etc
}

public 
class C extends A <C> {
   // etc
}


我在这里使用“可比较”只是说明可能使用通用参数“E”。 通用名词/遗产的使用是否有一个名称? 使用什么?

我的印象是,这让抽象的类别能够提供一种方法的共同执行(例如比较To),而不必在子类中提供这种方法。 然而,在这种例子中,与一种继承方法不同的是,它会限制子类比较。 对于同一子类而不是任何“A”子类的其他情况。 这一权利是否合理?

不管怎么说,只要有预示,就已经看到这一点,并且知道情况。

感谢!

最佳回答
问题回答

我认为,这通常只是一种复习性通用型。 正如Tom Hawtin指出的,你可能想要A类和E类,扩大A<E>> 这种模式的最显著用途是 j。 Enum(你可能知道你选择了比较和比较;E>作为你的接口)。

它没有名称,一般不有用。 也许写这封信的人没有认识到他们可以这样写:

class A<E> implements Comparable<E>

My impression is that this allows the abstract class to provide a common implementation of a method (such as compareTo) without having to provide it in the subclasses.

不超过<条码>级A<E>。

However, in this example, unlike an inherited method it would restrict subclasses to invoking compareTo on other instances of the same subclass, rather than any "A" subclass. Does this sound right?

无,这是错误的。 它仅限于在<条码>上援引<条码>compareTo>,无论在何种<条码>上。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签