Tôi đã không google vấn đề này. Tại sao dòng này lại tạo ra một lỗi biên dịch.Mã với Generics sẽ không biên dịch
wrapper.doSmth(wrapper.getCurrent());
Tôi đang sử dụng java 7.
public class App {
Wrapper<?> wrapper;
class Generic<T>{
}
class Wrapper<T>{
Generic<T> current;
public void doSmth(Generic<T> generic){
}
public Generic<T> getCurrent(){
return current;
}
}
public void operation(){
wrapper.doSmth(wrapper.getCurrent());
}
}
Lỗi này là:
Error:(25, 24) java: method doSmth in class App.Wrapper<T> cannot be applied to given types;
required: App.Generic<capture#1 of ?>
found: App.Generic<capture#2 of ?>
reason: actual argument App.Generic<capture#2 of ?> cannot be converted to conf.App.Generic<capture#1 of ?> by method invocation conversion
Bạn có thể đăng lỗi biên dịch thực tế không? – Waterbagel
@Waterbagel Tôi đã chỉnh sửa bài đăng của mình để bao gồm thông báo lỗi – doctorgester
Và có thể bạn có thể cho chúng tôi biết mã này được cho là như thế nào; bạn có ý định giải quyết vấn đề gì. – GhostCat