我的java編譯器抱怨說我的代碼使用「未檢查或不安全的操作」。任何想法哪些行是在兩個代碼片段中造成的?爲什麼我的代碼會導致編譯器標記「unchecked或unsafe operations」警告?
@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壓制它,但我想知道原因。任何人都可以幫忙
重新編譯'-Xlint:unchecked'瞭解更多詳情。 – oldrinb
刪除@SuppressWarnings(「unchecked」),告訴你哪些行導致問題。 – kosa
哇......這些都是很長的名字! :) – Jonatan