【问题标题】:Recompile with -Xlint : unchecked for details使用 -Xlint 重新编译:详细信息未选中
【发布时间】:2019-05-31 19:17:56
【问题描述】:

大家好,我的代码中有此警告。我尝试使用

进行编译

@SuppressWarnings("未选中")

它编译但在执行时程序找不到主类。

我该如何解决这个问题?

代码下方:

import java.util.*;

@SuppressWarnings("unchecked")

class ProgRub {
    public static void main(String argv[]) {
        Hashtable rubrica = new Hashtable(20);
        String chiave, valore;
        Menu mioMenu = new Menu();
        int scelta;
        scelta = (int) mioMenu.scelta();

        while (scelta != 5) {
            if (scelta == 1) {
                chiave = mioMenu.leggiDato("Nome:");
                valoe = mioMenu.leggiDato("Valore:");
                rubrica.put(chiave, valore);
            } else if (scelta == 2) {
                chiave = mioMenu.leggiDato("Nome:");
                rubrica.remove(chiave);
            } else if (scelta == 3) {
                Iterator i = rubrica.keySet().iterator();
                while (i.hasNext()) {
                    chiave = (String) i.next();
                    valore = (String) rubrica.get(chiave);
                    System.out.println(chiave + "tel." + valore);
                }
            }

            else if (scelta == 4) {
                chiave = mioMenu.leggiDato("Nome:");
                if (rubrica.contains(chiave)) {
                    valore = (String) rubrica.get(chiave);
                    System.out.println("Telefono:" + valore);
                }

                else {
                    System.out.println("Nominativo inesistente.");
                }
            }
            scelta = (int) mioMenu.scelta();
        }

        System.out.println("Fine programma.");
    }
}

【问题讨论】:

  • 欢迎来到 Stack Overflow!您是否确认您正在正确的目录中使用正确的命令运行命令? (另外,请edit您的问题并格式化您的代码,因为它很难阅读。)
  • @JoeC 是的,目录是正确的。现在谢谢我编辑问题

标签: java compilation warnings hashtable deprecated


【解决方案1】:

您正在使用 HashtableIterator 作为原始类型。如果将它们分别用作Hashtable<String, String>Iterator<String>

  • 您不必取消“未检查”警告,并且
  • 您可以摆脱一堆类型转换。

要了解更多信息,我建议您花时间阅读 Java 泛型:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多