아... 보다 많은 자료를 아직도 몰라.Enum < e extends Enum< E> >;;.

지금 열거형 같은 소스 코드 중에 이런 정의 있다:
Enum <E extends Enum<E>>

인터넷에서 보면 많은 사람들이 글을 다 볼 수 없는 좀 설명 좀 잘 좀 만들었어.

한편 동봉하니, 외국에서 사이트에 따르면 하지만 영어 좋지 않다.야!. . .

As a type that can only be instantiation for its subtypes, and those subtypes will inherit some useful methods, some of which take subtype arguments (or otherwise depend on the subtype).
The context in which " Enum<E extends Enum<E>> " appears is the declaration of the Enum class in package java.lang :
public abstract class Enum<E extends Enum<E>> {
...
}
The type Enum is the common base class of all enumeration types. In Java an enumeration type such as Color is translated into a class Color that extends Enum<Color> . The purpose of the superclass Enum is to provide functionality that is common to all enumeration types.
Here is a sketch of class Enum :

public abstract class Enum<E extends Enum<E>> implements Comparable<E >, Serializable {
private final String name;
public final String name() { ... }
private final int ordinal;
public final int ordinal() { ... }

protected Enum(String name, int ordinal) { ... }

public String toString() { ... }
public final boolean equals(Object other) { ... }
public final int hashCode() { ... }
protected final Object clone() throws CloneNotSupportedException { ... }
public final int compareTo( E o) { ... }

public final Class<E > getDeclaringClass() { ... }
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) { ... }
}
The surprising feature in the declaration " Enum<E extends Enum<E>> " is the fact that the newly defined class Enum and its newly defined type parameter E appear in the bound of that same type parameter. It means that the Enum type must be instantiated for one of its subtypes. In order to understand why this makes sense, consider that every enum type is translated into a subtype of Enum .
Here is the contrived enum type Color :

enum Color {RED, BLUE, GREEN}
The compiler translates it into the following class:
public final class Color extends Enum<Color> {
public static final Color[] values() { return (Color[])$VALUES.clone(); }
public static Color valueOf(String name) { ... }
private Color(String s, int i) { super(s, i); }

public static final Color RED;
public static final Color BLUE;
public static final Color GREEN;

private static final Color $VALUES[];

static {
RED = new Color("RED", 0);
BLUE = new Color("BLUE", 1);
GREEN = new Color("GREEN", 2);
$VALUES = (new Color[] { RED, BLUE, GREEN });
}
}
The inheritance has the effect that the Color type inherits all the methods implemented in Enum<Color> . Among them is the compareTo method. The Color.compareTo method should probably take a Color as an argument. In order to make this happen class Enum is generic and the Enum.compareTo method takes Enum 's type parameter E as an argument. As a result, type Color derived from Enum<Color> inherits a compareTo method that takes a Color as and argument, exactly as it should.

If we dissect the declaration " Enum<E extends Enum<E>> " we can see that this pattern has several aspects.

First, there is the fact that the type parameter bound is the type itself: " Enum <E extends Enum <E>> ". It makes sure that only subtypes of type Enum are permitted as type arguments. (Theoretically, type Enum could be instantiated on itself, like in Enum<Enum> , but this is certainly not intended and it is hard to imagine a situation in which such an instantiation would be useful.)

Second, there is the fact that the type parameter bound is the parameterized type Enum <E> , which uses the type parameter E as the type argument of the bound. This declaration makes sure that the inheritance relationship between a subtype and an instantiation of Enum is of the form " X extends Enum<X> ". A subtype such as " X extends Enum<Y> " cannot be declared because the type argument Y would not be within bounds; only subtypes of Enum<X> are within bounds.

Third, there is the fact that Enum is generic in the first place. It means that some of the methods of class Enum take an argument or return a value of an unknown type (or otherwise depend on an unknown type). As we already know, this unknown type will later be a subtype X of Enum<X> . Hence, in the parameterized type Enum<X> , these methods involve the subtype X , and they are inherited into the subtype X . The compareTo method is an example of such a method; it is inherited from the superclass into each subclass and has a subclass specific signature in each case.

To sum it up, the declaration " Enum<E extends Enum<E>> " can be decyphered as: Enum is a generic type that can only be instantiated for its subtypes, and those subtypes will inherit some useful methods, some of which take subtype specific arguments (or otherwise depend on the subtype).

까지

글쓴이 미경 작성일 2015-01-21 09:34

너 무슨 보고도 몰라?이 단락의 영어 모르겠다, 아니면 이 제네릭 정의 모르겠다?

글쓴이 주원 작성일 2015-01-21 12:09

Enum<E extends Enum<E>> 표시 제네릭 인자 바로 자신을 이렇게 코드 일종의 은 이런

public class Test extends Enum<Test>

물론 이 코드 번역 통과할 수 있기 때문에 지금 java 컴파일러 위에 대해 제한을 java.lang.Enum 추상화 못 지금 코드 속에서 진행되었다 extends 것이다

글쓴이 주원 작성일 2015-01-21 15:46

E 마땅히 후술 코드 중에 쓰는 형식 선언.
E 것은 상속 및 Enum<E>, E 그것을 하위 클래스.
때문에 E 아직 나타나지 왜 알 수 있을 Enum<E>한 어떤 종류의??

글쓴이 미경 작성일 2015-01-21 15:48

또 말이 분명히 좀 제네릭 도대체 E 아니면 Enum 둘 달라요.

글쓴이 미경 작성일 2015-01-21 16:36