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 来压制它,但我想知道原因。任何人都可以帮忙吗?

4

1 回答 1

1

类是一个参数化的类。您应该使用Class<?>(或必要时更具体的东西)。当然,编译器错误可能会准确地告诉您问题出在哪里。

此外,这一行是未经检查的演员表,但你别无选择:

channelAccounts = (ArrayList<ChannelAccount>)channelAccountStringsParserImplementedParseMethod.invoke(channelAccountStringsParserImplementedInstance, responseContent);
于 2012-08-31T19:54:30.197 回答