2012-08-31 4 views
0

내 Java 컴파일러에서 코드에서 "확인되지 않거나 안전하지 않은 작업"을 사용한다고 불평하고 있습니다. 두 코드 스 니펫에서 어떤 선이 그 점을 일으키고 있는지 아시겠습니까?내 코드가 컴파일러에서 "확인되지 않거나 안전하지 않은 작업"경고를 발생시키는 이유는 무엇입니까?

@SuppressWarnings("unchecked") 
private final void prepareChannelAccountStringsParserImplementedClassConstructor() { 
    try { 
     String channelAccountStringsParserImplementedClassName = channelIdentifier + "AccountStringsParser"; 
     Class channelAccountStringsParserImplementedClass = Class.forName(channelAccountStringsParserImplementedClassName); 
     Class[] channelAccountStringsParserImplementedClassArguments = new Class[1]; 
     channelAccountStringsParserImplementedClassArguments[0] = String.class; 
     channelAccountStringsParserImplementedClassConstructor = channelAccountStringsParserImplementedClass.getConstructor(channelAccountStringsParserImplementedClassArguments); 
     channelAccountStringsParserImplementedParseMethod = channelAccountStringsParserImplementedClass.getMethod("parse", String.class); 
     channelAccountStringsParserGetRequestIDMethod = channelAccountStringsParserImplementedClass.getMethod("getRequestID"); 
    } catch (ClassNotFoundException classNotFoundException) { 
     NotifyMeListenersLogsDB notifyMeListenersLogsDB = DatabaseController.getInstance().getNotifyMeListenersLogsDB(); 
     notifyMeListenersLogsDB.writeDeveloperException(classNotFoundException); 
    } catch (NoSuchMethodException noSuchMethodException) { 
     NotifyMeListenersLogsDB notifyMeListenersLogsDB = DatabaseController.getInstance().getNotifyMeListenersLogsDB(); 
     notifyMeListenersLogsDB.writeDeveloperException(noSuchMethodException); 
    } 
} 

    @SuppressWarnings("unchecked") 
public synchronized final void requestChannelAccountsCompletionSuccess(String responseContent) { 
    Object channelAccountStringsParserImplementedInstance; 
    ArrayList<ChannelAccount> channelAccounts = null; 
    String requestID = null; 
    try { 
     channelAccountStringsParserImplementedInstance = channelAccountStringsParserImplementedClassConstructor.newInstance(responseContent); 
     channelAccounts = (ArrayList<ChannelAccount>) channelAccountStringsParserImplementedParseMethod.invoke(channelAccountStringsParserImplementedInstance, responseContent); 
     requestID = (String) channelAccountStringsParserGetRequestIDMethod.invoke(channelAccountStringsParserImplementedInstance); 
    } catch (InstantiationException instantiationException) { 
     NotifyMeListenersLogsDB notifyMeListenersLogsDB = DatabaseController.getInstance().getNotifyMeListenersLogsDB(); 
     notifyMeListenersLogsDB.writeDeveloperException(instantiationException); 
    } catch (IllegalAccessException illegalAccessException) { 
     NotifyMeListenersLogsDB notifyMeListenersLogsDB = DatabaseController.getInstance().getNotifyMeListenersLogsDB(); 
     notifyMeListenersLogsDB.writeDeveloperException(illegalAccessException); 
    } catch (InvocationTargetException invocationTargetException) { 
     NotifyMeListenersLogsDB notifyMeListenersLogsDB = DatabaseController.getInstance().getNotifyMeListenersLogsDB(); 
     notifyMeListenersLogsDB.writeDeveloperException(invocationTargetException); 
    } 
    channelAccountStringsParserImplementedInstance = null; 
    try { 
     startChannelConnections(channelAccounts); 
     isStarted = true; 
     LoadBalancer.getInstance().sendSuccessAcknowledgement(requestID); 
    } catch (NotifyMeListenersApplicationInitializationException notifyMeListenersApplicationInitializationException) { 
     NotifyMeListenersLogsDB notifyMeListenersLogsDB = DatabaseController.getInstance().getNotifyMeListenersLogsDB(); 
     notifyMeListenersLogsDB.writeNotifyMeListenersException(notifyMeListenersApplicationInitializationException); 
     System.exit(1); 
    } 
} 

당연히 나는 그것을 억제하기 위해 @SuppressWarnings을 넣었지만 그 원인을 알고 싶습니다. 누구든지 도울 수 있니?

+0

다시 컴파일 -Xlint'와 자세한 세부 사항에 대한 unchecked'을. – oldrinb

+1

문제를 일으키는 줄을 알려주는 @SuppressWarnings ("선택 취소됨")을 제거하십시오. – kosa

+3

와우 .. 그것들은 긴 이름입니다! :) – Jonatan

답변

1

클래스는 매개 변수가있는 클래스입니다. Class<?> (또는 필요한 경우 더욱 구체적인 내용)을 사용해야합니다. 물론 컴파일러 오류로 인해 문제의 위치가 정확히 알려질 것입니다.

또한,이 라인은 검사되지 않은 캐스트,하지만 당신은 그 일에 선택의 여지가 없다 :

channelAccounts = (ArrayList<ChannelAccount>)channelAccountStringsParserImplementedParseMethod.invoke(channelAccountStringsParserImplementedInstance, responseContent); 
+0

... 당신에 대해 걱정할 필요가 자세한 정보 표시 및 반복 작업의 당신은 어떤 솔루션이이 의미, 나는이 @SuppressWarning과 함께 살기? – ikevin8me

+1

@ikevinjp -'invoke()'호출의 결과에 대해 예, Java에서이를 체크하지 않은 채로 해결할 수 없습니다 (리플렉션은 제네릭과 잘 맞지 않습니다). – jtahlborn