When using JDK 1.8 with the compiler option `-source 1.6` or `-source
1.7` or JDK 1.7 with the `-source 1.6` compiler option, compilation
failed with:
```
src/main/java/org/libvirt/event/DomainEvent.java:63: error: incompatible types: inference
variable T#1 has incompatible upper bounds Enum<T#2>,T#3
return this.type.obtain(this.detail);
^
where T#1,T#2,T#3 are type-variables:
T#1 extends Enum<T#1> declared in method <T#1>obtain(int)
T#2 extends T#3
T#3 extends Enum<T#3>,DomainEventDetail declared in method
<T#3>getDetail()
```
Actually, it compiles just fine using a 1.6, 1.7 or 1.8 Java compiler
when omitting the -source option.
Remove the `obtain` method altogether and use the `safeAt` method
directly instead.
---
src/main/java/org/libvirt/event/DomainEvent.java | 4 +++-
src/main/java/org/libvirt/event/DomainEventType.java | 7 -------
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/libvirt/event/DomainEvent.java
b/src/main/java/org/libvirt/event/DomainEvent.java
index 21fac60..56234ad 100644
--- a/src/main/java/org/libvirt/event/DomainEvent.java
+++ b/src/main/java/org/libvirt/event/DomainEvent.java
@@ -60,7 +60,9 @@ public final class DomainEvent {
* {@link DomainEventDetail} interface
*/
public <T extends Enum<T> & DomainEventDetail> T getDetail() {
- return this.type.obtain(this.detail);
+ @SuppressWarnings("unchecked") T detail =
(T)this.type.safeAt(this.detail);
+
+ return detail;
}
@Override
diff --git a/src/main/java/org/libvirt/event/DomainEventType.java
b/src/main/java/org/libvirt/event/DomainEventType.java
index b675d8b..c42043d 100644
--- a/src/main/java/org/libvirt/event/DomainEventType.java
+++ b/src/main/java/org/libvirt/event/DomainEventType.java
@@ -46,13 +46,6 @@ public enum DomainEventType {
details = d;
}
- @SuppressWarnings("unchecked")
- <T extends Enum<T>> T obtain(final int detail) {
- return (T)safeAt(detail);
- }
-
- // this method is only necessary for OpenJDK 6 which does not
- // compile calls to `obtain(d)` in some circumstances
Object safeAt(final int detail) {
final int index = Math.min(this.details.length - 1, detail);
return this.details[index];
--
2.5.1