Üzerinde denetim bulunmayan bir dış kütüphane kullanıyorum. Bu bir yöntemi uygulamak için beni gerektirir ama gereklidir türü dönmek nasıl bilmiyorum: oUyumsuz türler bir Sınıf döndürürken
public MyClass implements AnInterface<String> {
...
}
Ben de bu çalıştı, ama:
@Override
public Optional<Class<? extends AnInterface<?>>> getCustomClass() {
return Optional.of(MyClass.class);
// compiler is giving error at the above line:
// error: incompatible types: inference variable T has incompatible bounds
// equality constraints: Class<? extends AnInterface<?>>
// lower bounds: Class<MyClass>
// where T is a type-variable:
// T extends Object declared in method <T>of(T)
}
Sınıfım çalışmaz:
:@Override
public Optional<Class<? extends AnInterface<?>>> getCustomClass() {
Optional<Class<? extends AnInterface<?>> clazz = MyClass.class;
// this time the compiler gives error at the above line:
// error: incompatible types: Class<MyClass> cannot be converted to Class<? extends AnInterface<?>>
return clazz;
}
Ayrıca ya çalışmıyor başka bir çalıştı 210
@Override
public Optional<Class<? extends AnInterface<?>>> getCustomClass() {
Optional<Class<? extends AnInterface> clazz = MyClass.class;
return clazz;
// this time the compiler gives error at the above line:
// error: incompatible types: inference variable T has incompatible bounds
// equality constraints: Class<? extends PropertyEditor<?>>
// lower bounds: Class<CAP#1>
// where T is a type-variable:
// T extends Object declared in method <T>of(T)
// where CAP#1 is a fresh type-variable:
// CAP#1 extends PropertyEditor from capture of ? extends PropertyEditor
}
Özel sınıfın nasıl döndürüleceği hakkında herhangi bir fikriniz var mı?
JDK versiyonu:
DÜZENLEME 8u77: sınıfları böyle iç içe gibidir:
geçersiz kılınmış yöntemi uygularken Yani nedense derleyici joker tarafından karıştırılanpublic abstract class ParentClass<T> {
public abstract T method();
public class ImplementationClass implements ExternalLibraryInterface {
@Override
public Optional<Class<? extends AnotherExternalLibraryInterface<?>>> getCustomClass() {
return Optional.of(MyClass.class);
// compiler is giving error at the above line:
// error: incompatible types: inference variable T has incompatible bounds
// equality constraints: Class<? extends AnotherExternalLibraryInterface<?>>
// lower bounds: Class<MyClass>
// where T is a type-variable:
// T extends Object declared in method <T>of(T)
}
MyClass implements AnotherExternalLibraryInterface<String>{
...
}
}
}
dış arabirim. Tüm sınıfları kendi dosyalarına taşıdıktan sonra her şey iyi çalışıyor. Ham Opsiyonel tip çalışmalara
return (Optional)(Optional.of(MyClass.class));
1.8.0_74 ile yeniden olamaz. 'Return Optional.of (MyClass.class);' beklendiği gibi çalışır. Test: 'public Opsiyonel
>> getCustomClass() { \t \t return Optional.of (MyClass.class); \t} \t arayüz AnInterface {} \t sınıf sınıfı bir AnInterface {} ' –
Tunaki
@Tunaki uygular. Bu garip, sorudaki kod pasajı (basitleştirilmiş versiyonu) aslında işe yarıyor. Kodun tam sürümü derleme hatası verir. Kesinlikle derleyici hatasına neden olan dönüş çizgisidir. Optional.empty() öğesini döndürürken oluşturulur; – zhywu