2014-11-29 9 views
1

는 다음과 같은 방법을 감안할 때 : 일반 메서드가 지정된 메서드 서명과 호환되지 않습니다?

public <E> void bindContentBidirectional(final String fieldPath, 
     final String itemFieldPath, final Class<?> itemFieldPathType, 
     final ObservableList<E> list, final Class<E> listValueType, 
     final SelectionModel<E> selectionModel, 
     final String selectionModelItemMasterPath) 

내가 나의 이해에 정정 오전, 그 난의 종류로서 ObservableList<PrintablePredicate<SomeClass>>이있는 경우 :

final ObservableList<E> list 

(즉이 작동하지 않을 수 있다는 E = PrintablePredicate<SomeClass>입니다 왜냐하면 다음 인수 때문에 :

final Class<E> listValueType) 

나는 단지 PrintablePredicate.class를 쓸 수 있고, PrintablePredicate.class는 유전자로 쓸 수 없기 때문에 유형이 구체화되지 않았습니다. 즉, bindContentBidirectional에 대한 지정된 메서드 서명은 E가 제네릭 형식 인수를 갖도록 모든 E와 호환되지 않습니다. 구체적인 코드 시나리오에서 모두 함께 퍼팅

, 우리가 말 :

@FXML private CheckListView<PrintablePredicate<Miner>> profileConditions;  
private MinerMonitorProfile minerMonitorProfile; 

private void initialize() { 
    BeanPathAdapter<MinerMonitorProfile> minerMonitorProfileBPA = new BeanPathAdapter<> (this.minerMonitorProfile); 
    minerMonitorProfileBPA.bindContentBidirectional("conditions", null, String.class, this.profileConditions.getItems(), PrintablePredicate.class, null, null); 
} 

컴파일러는 말한다 :

유형 BeanPathAdapter<MinerMonitorProfile>의 방법 bindContentBidirectional(String, String, Class<?>, ObservableList<E>, Class<E>, SelectionModel<E>, String)이 인수 적용되지 않습니다 (String , null, Class<String>, ObservableList<PrintablePredicate<Miner>>, Class<PrintablePredicate>, null, null)

어쨌든이 문제가 있습니까? 감사!

참고 : this.profileConditions.getItems() 반환 입력에서와 같이 메서드 호출을 매개 변수화하는 것이 ObservableList<PrintablePredicate<Miner>>

또한 참고 :

minerMonitorProfileBPA.<PrintablePredicate<Miner>>bindContentBidirectional("conditions", null, String.class, this.profileConditions.getItems(), PrintablePredicate.class, null, null); 

문제를 완화하지 않습니다.

답변

1

필자가 그런 종류의 문제 (매개 변수화 된 클래스에 일반 클래스를 캐스팅하는 경우)가 있습니까? 컴파일러를 우회하기 위해 이중 캐스팅을 사용합니다.

그래서 귀하의 경우에는 내가 bindContentBidirectional 함수에 PrintablePredicate.class 매개 변수를 전달 할 때

(Class<PrintablePredicate<Miner>>)(Class<?>) PrintablePredicate.class 

를 작성할 수 같아요.


편집 : 나는 단순히 클래스에 PrintablePredicate.class 캐스팅 것을 발견 또는 할당 (내가 왜하지만 알아 보았하지 않습니다, 그것은 내 *을 .class는 Class 형의 이미 있기 때문에 의견에 좀 불필요한 것) javac 1.8.0_25를 사용하여 메소드에 전달하기 전에 변수에 전달합니다.때문에 (이 버그 때문에 이해가되지 않습니다 예,) 오픈 JDK에서이 유사한 컴파일러의 버그가

(Class)PrintablePredicate.class 

그래서 당신의 오류가있을 수 있습니다 : 그 때문에 어쩌면 당신은 대신 위의 코드의이를 사용해야합니다 : 요약으로 https://bugs.openjdk.java.net/browse/JDK-8028682


다음 내 결과, (다만 변수에 객체를 할당하거나)이 '더블 캐스팅'트릭 물건 컴파일러는 "이해"하기 위해 "더 쉽게"도움이 될 수 있습니다 후 당신의 코드와 같은 버그가있을 때 (LOL, 추측 할 수밖에없는 일종의 웃기는 일이지만, 때로는 심지어 당신을 믿을 수도 없다는 것을 보여줍니다. 전자 컴파일러).

+0

실제로 작동했습니다. 매우 감사합니다. 우연히 (또는 다른 누군가) 내가 겉으로보기에는 마법 같은 이중 주조에 대해 배울 수있는 자원이 있습니까? 감사합니다.) – brcolow

+0

불행히도 나는 그것에 대해 읽지 않았습니다. 그것은 언젠가 그런 종류의 문제로 어려움을 겪었을 때 알게된 속임수입니다. 그 트릭이 무엇을 설명하려고하는지에 대한 대답에 더 많은 정보를 추가 할 것입니다. –

+0

흠 ... 솔직히 말하면 솔직히 말해서, 내가 발견 한 해킹의 일종이라고 생각합니다. 왜냐하면 코드가 먼저 클래스를 변수에 할당하면 코드가 작동하기 때문에 (예 : "class clazz = PrintablePredicate.class"를 사용하여 메서드 호출) 그 변수를 메서드에 전달하면됩니다. 그래서이 컴파일 오류가 자바 컴파일러에서 일종의 버그 일종의 경우 궁금합니다. –